好久没写题解了,今天来写个题解。


A – 问题 Generator

#include "bits/stdc++.h"
using namespace std;

#define int long long 
#define endl '
'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair 
#define vi vector
#define si set 
#define mi map
#define mc map
#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
templatebool chmin(T &a, const T &b) { if (bbool chmax(T &a, const T &b) { if (a>n>>m;
	string s;
	cin>>s;
	map 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<>t;
	while(t--){
		solve();
	}
}

B – Choosing Cubes

#include "bits/stdc++.h"
using namespace std;

#define int long long 
#define endl '
'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair 
#define vi vector
#define si set 
#define mi map
#define mc map
#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
templatebool chmin(T &a, const T &b) { if (bbool chmax(T &a, const T &b) { if (a>n>>f>>k;
	int x;
	vi a(n+1);
	for (int i=1;i>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"<k && pos<=k){
		cout<<"MAYBE"<k){
		cout<<"NO"<>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 '
'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair 
#define vi vector
#define si set 
#define mi map
#define mc map
#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
templatebool chmin(T &a, const T &b) { if (bbool chmax(T &a, const T &b) { if (a>n;
	vi a(n+1),b(n+1);
	for (int i=1;i>a[i];
	}
	for (int i=1;i>b[i];
	}
	map mp,mp1;
	for (int i=1;i>m;
	int fl=0;
	vi c;
	for (int i=1;i>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;ipos){
				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"<>t;
	while(t--){
		solve();
	}
}

D – GCD-sequence

思路:通过贪心来遍历没所以最多只能处理一个递减的情况,可以先开个数组记录一下递减的位置和递减的对数数量。一点要特判的是在边界的话,是可以直接删掉最外面的数的。然后可以直接遍历一次,每次都对删去中间那个a。看操作后,是不是可以消去所有的不递增。

可以看代码理解。

#include "bits/stdc++.h"
using namespace std;

#define int long long 
#define endl '
'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair 
#define vi vector
#define si set 
#define mi map
#define mc map
#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
templatebool chmin(T &a, const T &b) { if (bbool chmax(T &a, const T &b) { if (a>n;
	vi a(n+1);
	for (int i=1;i>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;i1){
				tmp1=b[i-1];
			}
			if(itmp2){
				cnt++;
			}
			if(tmp2>tmp3){
				cnt++;
			}
			
			if(cnt==0){
				fl=1;
			}
			
			
		
	}
	
	
	if(fl){
		cout<<"yes"<<endl;
		return ;
	}
	else {
		cout<<"NO"<>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 '
'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair 
#define vi vector
#define si set 
#define mi map
#define mc map
#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
templatebool chmin(T &a, const T &b) { if (bbool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
const int INF =1e18;

	map mpx,mpy;
void solve()
{
	int n,m;
	cin>>n>>m;
	vector<vector> a(n+1,vector(m+1));
	vector<vector> b(n+1,vector(m+1));

	int fl=0;
	for (int i=1;i<=n;i++){
		for (int j=1;j>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>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"<>t;
	while(t--){
		solve();
	}
}


Field Division (easy version)

思路:从底下往上算,每次都修改最左边的值和最下面的值,并加上左边的面积,就是总面积了。

其中x轴的排序时从大到小,y轴的排序是从小到大。 如果想移除这个台灯后面积变大,这个台灯必须得位于边界,并且两个相邻的边为边界才行, 这个点也是边界改变的点。 所以每次改变边界的时候都把这个点标记。

#include "bits/stdc++.h"
using namespace std;

#define int long long 
#define endl '
'
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define all(x) x.begin(),x.end()
#define pi pair 
#define vi vector
#define si set 
#define mi map
#define mc map
#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
templatebool chmin(T &a, const T &b) { if (bbool 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.yy.x;
	}
}


void solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	
	for (int i=1;i>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;ia[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++){
		coutt;
	while(t--){
		solve();
	}
}

本站无任何商业行为
个人在线分享 » Codeforces Round 950 (Div. 3)
E-->
© 2018 Theme by - 本站无任何商业行为 & WordPress Theme. All rights reserved 蒙ICP备2023002302号-2