Codeforces Round 950 (Div. 3)

好久沒寫題解了,今天來寫個題解。


A - 問題 Generator

#include "bits/stdc++.h"
using namespace std;#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair<int,int> 
#define vi vector<int>
#define si set<int> 
#define mi map<int,int>
#define mc map<char,int>
#define YES cout<<"Yes"<<endl;
#define NO  cout<<"No"<<endl;
#define pb(x) push_back(x);
#define fi first
#define sc second
#define is insert
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
const int INF =1e18;
void solve()
{int n,m;cin>>n>>m;string s;cin>>s;map<char,int> mp;//int n=s.size();for (int i=0;i<n;i++){mp[s[i]]++;}int sum=0;for (char i='A';i<='G';i++){if(mp[i]<m){sum+=(m-mp[i]);}}cout<<sum<<endl;}signed main()
{IOSint t;cin>>t;while(t--){solve();}
}

B - Choosing Cubes

#include "bits/stdc++.h"
using namespace std;#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair<int,int> 
#define vi vector<int>
#define si set<int> 
#define mi map<int,int>
#define mc map<char,int>
#define YES cout<<"Yes"<<endl;
#define NO  cout<<"No"<<endl;
#define pb(x) push_back(x);
#define fi first
#define sc second
#define is insert
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
const int INF =1e18;
void solve()
{int n,f,k;cin>>n>>f>>k;int x;vi a(n+1);for (int i=1;i<=n;i++){cin>>a[i];if(i==f){x=a[i];}}int pos=0;sort(a.begin()+1,a.end());reverse(a.begin()+1,a.end());for (int i=1;i<=n;i++){if(a[i]==x){pos=i;break;}}int cnt=pos;for (int i=pos+1;i<=n;i++){if(a[i]==a[pos]){cnt++;}else {break;}}if(cnt<=k){cout<<"YES"<<endl;}else if (cnt>k && pos<=k){cout<<"MAYBE"<<endl;}else if(cnt>k){cout<<"NO"<<endl;}}signed main()
{IOSint t;cin>>t;while(t--){solve();}
}

A和B 都是簡單的模擬題,按照題意來寫就行,可以參考代碼。

C - Sofia and the Lost Operations

思路:給出的m個元素可以分為三類來看,一類是需要改成b的,一類是和b相等的元素,還有一類是ab 中都沒有的元素。 而這第三類元素必須要被第一類和第二類覆蓋掉。所以只需要倒敘找最后的元素是不是第一第二類元素。? (可以使用map 來存第一第二類元素)。

#include "bits/stdc++.h"
using namespace std;#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair<int,int> 
#define vi vector<int>
#define si set<int> 
#define mi map<int,int>
#define mc map<char,int>
#define YES cout<<"Yes"<<endl;
#define NO  cout<<"No"<<endl;
#define pb(x) push_back(x);
#define fi first
#define sc second
#define is insert
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
const int INF =1e18;
void solve()
{int n;cin>>n;vi a(n+1),b(n+1);for (int i=1;i<=n;i++){cin>>a[i];}for (int i=1;i<=n;i++){cin>>b[i];}map<int,int> mp,mp1;for (int i=1;i<=n;i++){if(a[i]!=b[i]){mp[b[i]]++;}else {mp1[b[i]]=1;}}int m;cin>>m;int fl=0;vi c;for (int i=1;i<=m;i++){int x;cin>>x;c.push_back(x);}int pos;for (int i=m-1;i>=0;i--){if(mp[c[i]]|| mp1[c[i]]){pos=i;break;}}for (int i=0;i<m;i++){if(mp[c[i]]){mp[c[i]]--;}else if(mp1[c[i]]){continue;}else {if(i>pos){fl=1;}}}if(fl==1){cout<<"NO"<<endl;return ;}for (int i=1;i<=n;i++){if(mp[b[i]]){cout<<"NO"<<endl;return ;}}cout<<"YES"<<endl;}signed main()
{IOSint t;cin>>t;while(t--){solve();}
}

D - GCD-sequence

思路:通過貪心來遍歷沒所以最多只能處理一個遞減的情況,可以先開個數組記錄一下遞減的位置和遞減的對數數量。一點要特判的是在邊界的話,是可以直接刪掉最外面的數的。然后可以直接遍歷一次,每次都對刪去中間那個a。看操作后,是不是可以消去所有的不遞增。

可以看代碼理解。

#include "bits/stdc++.h"
using namespace std;#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair<int,int> 
#define vi vector<int>
#define si set<int> 
#define mi map<int,int>
#define mc map<char,int>
#define YES cout<<"Yes"<<endl;
#define NO  cout<<"No"<<endl;
#define pb(x) push_back(x);
#define fi first
#define sc second
#define is insert
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
const int INF =1e18;
void solve()
{int n;cin>>n;vi a(n+1);for (int i=1;i<=n;i++){cin>>a[i];}int ans=0;vi b(n),c(n+1);for (int i=1;i<=n-1;i++){b[i]=__gcd(a[i],a[i+1]);}for (int i=1;i<n-1;i++){if(b[i+1]<b[i]){c[i]=1;ans++;}}if(ans==0){cout<<"YES"<<endl;return ;}if(ans==1 &&c[1]==1){cout<<"YES"<<endl;return ;}if(ans==1 &&c[n-2]==1){cout<<"YES"<<endl;return  ;}int fl=0;for (int i=1;i<n-1;i++){int tmp1=0,tmp2=0,tmp3=1e9;tmp2=__gcd(a[i],a[i+2]);int cnt=ans;if(c[i]) cnt--;if(c[i-1]) cnt--;if(c[i+1] )  cnt--;if(i>1){tmp1=b[i-1];}if(i<n-2){tmp3=b[i+2];}if(tmp1>tmp2){cnt++;}if(tmp2>tmp3){cnt++;}if(cnt==0){fl=1;}}if(fl){cout<<"yes"<<endl;return ;}else {cout<<"NO"<<endl;}
}signed main()
{IOSint t;cin>>t;while(t--){solve();}
}

E - Permutation of Rows and Columns

思路:其實就是看兩個矩陣的每行和每列的元素是不是一樣的。

所以用兩個map 分別存每個元素的x和 y坐標 然后最后看兩個矩陣的每一個元素的x和坐標是不是對應的。

#include "bits/stdc++.h"
using namespace std;#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair<int,int> 
#define vi vector<int>
#define si set<int> 
#define mi map<int,int>
#define mc map<char,int>
#define YES cout<<"Yes"<<endl;
#define NO  cout<<"No"<<endl;
#define pb(x) push_back(x);
#define fi first
#define sc second
#define is insert
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
const int INF =1e18;map<int,int> mpx,mpy;
void solve()
{int n,m;cin>>n>>m;vector<vector<int>> a(n+1,vector<int>(m+1));vector<vector<int>> b(n+1,vector<int>(m+1));int fl=0;for (int i=1;i<=n;i++){for (int j=1;j<=m;j++){cin>>a[i][j];mpx[a[i][j]]=i;mpy[a[i][j]]=j;}}for (int i=1;i<=n;i++){for (int j=1;j<=m;j++){cin>>b[i][j];if(mpx[b[i][j]]!=mpx[b[i][1]] || mpy[b[i][j]]!=mpy[b[1][j]]){fl=1;}}}if(fl){cout<<"NO"<<endl;return ;}else {cout<<"yes"<<endl;}}signed main()
{IOSint t;cin>>t;while(t--){solve();}
}

Field Division (easy version)

思路:從底下往上算,每次都修改最左邊的值和最下面的值,并加上左邊的面積,就是總面積了。

其中x軸的排序時從大到小,y軸的排序是從小到大。 如果想移除這個臺燈后面積變大,這個臺燈必須得位于邊界,并且兩個相鄰的邊為邊界才行,?這個點也是邊界改變的點。 所以每次改變邊界的時候都把這個點標記。

#include "bits/stdc++.h"
using namespace std;#define int long long 
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair<int,int> 
#define vi vector<int>
#define si set<int> 
#define mi map<int,int>
#define mc map<char,int>
#define YES cout<<"Yes"<<endl;
#define NO  cout<<"No"<<endl;
#define pb(x) push_back(x);
#define fi first
#define sc second
#define is insert
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
const int INF =1e18;struct node{int x,y;int id;
}a[200010];bool cmp(node x,node y){if(x.x==y.x){return x.y<y.y;}else {return x.x>y.x;}
}void solve()
{int n,m,k;cin>>n>>m>>k;for (int i=1;i<=k;i++){cin>>a[i].x>>a[i].y;a[i].id=i;}sort(a+1,a+k+1,cmp);vi ans(k+1);int l=m+1,d=n;int sum=0;for (int i=1;i<=k;i++){if(l>a[i].y){ans[a[i].id]=1;sum+=(d-a[i].x)*(l-1);l=a[i].y;d=a[i].x;}}sum+=d*(l-1);cout<<sum<<endl;for (int i=1;i<=k;i++){cout<<ans[i]<<" ";}cout<<endl;}signed main()
{IOSint t;cin>>t;while(t--){solve();}
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/23752.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/23752.shtml
英文地址,請注明出處:http://en.pswp.cn/web/23752.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【Linux】(一)——Linux基礎和Linux命令基礎語法

目錄 Linux基礎Linux發行版本Linux終端Linux命令 Linux基礎 Linux&#xff0c;通常指的是GNU/Linux操作系統&#xff0c;這是一個開源且免費使用的類UNIX操作系統。它的核心組件——Linux內核&#xff0c;由林納斯托瓦茲&#xff08;Linus Torvalds&#xff09;在1991年10月5日…

Arthas使用教程——JVM常用命令

JVM相關命令 dashboard——當前系統的實時數據面板 顯示當前 tomcat 的實時信息。 使用方式&#xff1a;dashboard 數據說明 ID: Java 級別的線程 ID&#xff0c;注意這個 ID 不能跟 jstack 中的 nativeID 一一對應。 NAME: 線程名 GROUP: 線程組名 PRIORITY: 線程優先級…

Rocky Linux安裝與基礎配置

目錄 背景與起源 主要特點 目標用戶 發展前景 下載 安裝 常用配置命令&#xff1a; 更換鏡像源 Rocky Linux 是一個開源的、由社區驅動的操作系統&#xff0c;旨在使用 Red Hat Enterprise Linux&#xff08;RHEL&#xff09;源碼構建的下游二進制兼容發行版。以下是關于…

優思學院|一文看懂新版FMEA與FMEA的七大步驟

FMEA的起源 FMEA最早起源于20世紀40年代的美國軍工行業。當時&#xff0c;美國軍方為了提高武器系統的可靠性和安全性&#xff0c;開始使用FMEA來識別和評估潛在的故障模式及其影響。1949年&#xff0c;美國軍方發布了《軍用程序手冊》&#xff08;Military Procedures Handbo…

【Android面試八股文】在Java中重載和重寫是什么意思,區別是什么?

文章目錄 在Java中重載和重寫是什么意思,區別是什么?這道題想考察什么 ?考察的知識點考生應該如何回答重載(Overloading)重寫(Overriding)重載和重寫的區別在Java中重載和重寫是什么意思,區別是什么? 這道題想考察什么 ? Java基礎 考察的知識點 面向對象多態的基…

五種網絡IO模型

目錄 前言 文件描述符 為什么要多種io模型 同步IO 1.阻塞IO 2.非阻塞IO 3.多路復用IO&#xff08;事件驅動IO&#xff09; select: poll&#xff1a; epoll&#xff1a; 4.信號驅動IO 異步IO 區別 前言 文件描述符 首先我們了解一下文件描述符是什么&#xff1a;…

【Python報錯】已解決AttributeError: ‘method‘ object has no attribute ‘xxx‘

解決Python報錯&#xff1a;AttributeError: ‘method’ object has no attribute ‘xxx’ 在Python中&#xff0c;AttributeError通常表明你試圖訪問的對象沒有你請求的屬性或方法。如果你遇到了AttributeError: method object has no attribute xxx的錯誤&#xff0c;這通常意…

批量處理腳本,用于刪除指定目錄下3天前的備份文件和日志。

echo off echo 刪除3天前的備份文件和日志 set SrcDirD:\home set DaysAgo3 echo 準備刪除3天前的備份文件和日志 forfiles /p %SrcDir% /d -%DaysAgo% /c "cmd /c del /f /q /a path && rd /s /q path" echo 正在執行刪除&#xff0c;請稍等…… set SrcDi…

奇跡MU最強法師介紹

1、黑龍波 釋放出深淵中的黑龍之魂&#xff0c;對一定范圍內的目標造成中等程度傷害。 奧義&#xff1a; 怒哮——法師釋放出深淵龍魂的怨怒之力&#xff0c;在電閃雷鳴中中咆哮的龍魂將對敵人額外造成少量傷害。 魂陣——法師利用法陣控制黑龍之魂進行更大范圍的攻擊&…

如何使用SeaFile文件共享服務器結合內網穿透將家中電腦變成個人云盤

文章目錄 1. 前言2. SeaFile云盤設置2.1 Owncould的安裝環境設置2.2 SeaFile下載安裝2.3 SeaFile的配置 3. cpolar內網穿透3.1 Cpolar下載安裝3.2 Cpolar的注冊3.3 Cpolar云端設置3.4 Cpolar本地設置 4.公網訪問測試5.結語 1. 前言 本文主要為大家介紹&#xff0c;如何使用兩個…

opt 優化

【整理】深入理解拉格朗日乘子法&#xff08;Lagrange Multiplier) 和KKT條件 【amos注】&#xff1a;通俗易懂&#xff0c;讓人易于理解。

【Oracle篇】rman全庫異機恢復:從RAC環境到單機測試環境的轉移(第四篇,總共八篇)

&#x1f4ab;《博主介紹》&#xff1a;?又是一天沒白過&#xff0c;我是奈斯&#xff0c;DBA一名? &#x1f4ab;《擅長領域》&#xff1a;??擅長Oracle、MySQL、SQLserver、阿里云AnalyticDB for MySQL(分布式數據倉庫)、Linux&#xff0c;也在擴展大數據方向的知識面??…

【TensorFlow深度學習】深度學習中的損失函數種類與適用場景

深度學習中的損失函數種類與適用場景 深度學習中的損失函數種類與適用場景&#xff1a;精確度量模型誤差的藝術一、均方誤差&#xff08;Mean Squared Error, MSE&#xff09;二、交叉熵損失&#xff08;Cross-Entropy&#xff09;三、Hinge損失&#xff08;Margin Loss&#x…

ROS RViz觀測傳感器數據

ROS RViz觀測傳感器數據 The Robot Visualization Tool 可視化工具 機器人傳感器采集到的數據都可以圖形化的顯示在這個軟件里&#xff0c;機器人運算處理的中間結果&#xff0c;和即將要執行的目標指示&#xff0c;比如機器人對空間中某個物體進行識別后&#xff0c;我們可以…

【Linux】Linux工具——make/Makefile

1.背景 會不會寫makefile&#xff0c;從一個側面說明了一個人是否具備完成大型工程的能力一個工程中的源文件不計數&#xff0c;其按類型、功能、模塊分別放在若干個目錄中&#xff0c;makefile定義了一系列的 規則來指定&#xff0c;哪些文件需要先編譯&#xff0c;哪些文件需…

Edge 工作區是什么?它都有哪些作用?

什么是工作區 Edge 工作區是什么&#xff1f;它是微軟 Edge 瀏覽器中的一個功能&#xff0c;在幫助用戶更好地組織和管理他們的瀏覽會話。通過工作區&#xff0c;用戶可以創建多個獨立的瀏覽環境&#xff0c;每個工作區內包含一組相關的標簽頁和瀏覽器設置。這使得用戶能夠根據…

SQL進階day9————聚合與分組

目錄 1聚合函數 1.1SQL類別高難度試卷得分的截斷平均值 1.2統計作答次數 1.3 得分不小于平均分的最低分 2 分組查詢 2.1平均活躍天數和月活人數 2.2 月總刷題數和日均刷題數 2.3未完成試卷數大于1的有效用戶 1聚合函數 1.1SQL類別高難度試卷得分的截斷平均值 我的錯誤…

開放式耳機十大品牌推薦!怎么選耳機看這六招!

隨著耳機廠家的瘋狂內卷&#xff0c;以前讓學生黨望其項背的千元耳機技術&#xff0c;紛紛被廠家下沉至百元耳機&#xff0c;是以2024年始&#xff0c;百元開放式耳機以新物種、價低格而爆火。看到身邊朋友爭相購買開放式耳機&#xff0c;既當耳飾&#xff0c;又當耳機&#xf…

分享:2024年(第12屆)“泰迪杯”數據挖掘挑戰賽成績公示

2024年&#xff08;第12屆&#xff09;“泰迪杯”數據挖掘挑戰賽歷時兩個月順利結束。競賽采用盲審&#xff08;屏蔽參賽者信息&#xff1b;評審專家只能評閱非本區域作品&#xff1b;三位評閱專家同時評閱同一作品&#xff0c;超限調整后再取平均分&#xff09;&#xff0c;答…

redis做為緩存,mysql的數據如何與redis進行同步呢?

讓我們一步步來實現如何讓MySQL數據庫的數據和Redis緩存保持同步。想象一下&#xff0c;MySQL是一個大倉庫&#xff0c;存放著所有重要的貨物&#xff08;數據&#xff09;&#xff0c;而Redis則像是一個快速取貨窗口&#xff0c;讓你能更快拿到常用的東西。為了讓兩者保持一致…