Codeforces Round 640 (Div. 4) ABCDEFG

https://codeforces.com/contest/1352

不知道怎么的复制过来的代码容易歪,观看效果可能不大好。

这场古早div4,大题极其友好,除了E卡空间卡到我爆炸,别的都体验感极好。

A. Sum of Round Numbers

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e7+10,M=2023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL a[6]={0,10,100,1000,10000};
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
    	LL n;
    	cin>>n;
    	vector<LL> v;
    	for(int i=4;i>=1;i--)
    	{
    		if(n>a[i])
    		{
    			v.push_back(n/a[i]*a[i]);
    			n-=n/a[i]*a[i];
			}
		}
		if(n!=0)
		{
			v.push_back(n);
			n=0;
		}
		cout<<v.size()<<endl;
		for(int i=0;i<v.size();i++)
		{
			cout<<v[i]<<" ";
		}
		cout<<endl; 
		v.clear();
    }
    return 0;
}

B. Same Parity Summands

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e7+10,M=2023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
    	LL n,m;
    	cin>>n>>m;
    	if(n<m) cout<<"NO"<<endl;
		else if(n%m==0)
		{
			cout<<"YES"<<endl;
			for(int i=1;i<=m;i++)
			{
				cout<<n/m<<" ";
			}
			cout<<endl;
		}
		else
		{
			if((n-(m-1))%2==1&&n-(m-1)>0)//1 1 1
			{
				cout<<"YES"<<endl;
				for(int i=1;i<=m;i++)
				{
					if(i!=m) cout<<1<<" ";
					else cout<<n-(m-1)<<endl;
				}
			}
			else if((n-(m-1)*2)%2==0&&n-(m-1)*2>0)//2 2 2
			{
				cout<<"YES"<<endl;
				for(int i=1;i<=m;i++)
				{
					if(i!=m) cout<<2<<" ";
					else cout<<(n-(m-1)*2)<<endl;
				}
			}
			else cout<<"NO"<<endl;
		}
    }
    return 0;
}

C. K-th Not Divisible by n

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e7+10,M=2023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
    	LL n,k;
    	cin>>n>>k;
    	if(k<n) cout<<k<<endl;
    	else if(k==n) cout<<n+1<<endl;
    	else
    	{
    		LL last=k/n;
    		LL sum1=k;
    		LL sum2=k+last;
    		LL ans=k+last;
    		//cout<<last<<" "<<sum1<<" "<<sum2<<" "<<ans<<endl;
    		while(last!=0)
    		{
    			last=sum2/n-sum1/n;
    			ans+=last;
    			sum1=sum2;
    			sum2=ans;
				//cout<<last<<" "<<sum1<<" "<<sum2<<" "<<ans<<endl;
			}
			cout<<ans<<endl;
		}
    }
    return 0;
}

D. Alice, Bob and Candies

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e7+10,M=2023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
    	LL n;
    	cin>>n;
    	LL res=0;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    		res+=a[i];
		}
		LL alice=0,bob=0;
		LL alast=0,blast=0;
		LL t=0;
		for(int i=1,j=n; ; )
		{
			alast=0;
			while(i<=j&&alast<=blast)
			{
				alast+=a[i++]; 
			}
			alice+=alast;
			t++;
			if(i>j) break;
			blast=0;
			while(i<=j&&blast<=alast)
			{
				blast+=a[j--]; 
			}
			bob+=blast;
			t++;
			if(i>j) break;
		}
		cout<<t<<" "<<alice<<" "<<res-alice<<endl;
    }
    return 0;
}

E. Special Elements

题目大意:

给定一个长度为n的数组a,问我们能不能选取某一段的数字之和,然后同时数组中也存在这个和?

这样的和有几个?
input 
5
9
3 1 4 1 5 9 2 6 5
3
1 1 2
5
1 1 1 1 1
8
8 7 6 5 4 3 2 1
1
1
output 
5
1
0
4
0

memory limit per test:64 megabytes

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
//const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e5+10,M=2023;
//const LL mod=100000007;
//const double PI=3.1415926535;
//#define endl '\n'
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
    	int n;
    	//cin>>n;
    	scanf("%d",&n);
    	LL mp[N]={0},b[N];
    	for(int i=1;i<=n;i++)
    	{
    		//cin>>a[i];
    		scanf("%d",&b[i]);
    		mp[b[i]]++;
    		b[i]+=b[i-1];
	}
	int sum=0;
	for(int i=1;i<=n;i++)
        {
                for(int j=i+1;j<=n;j++)
                {
                      int res=b[j]-b[i-1];
                      if(res<=n&&mp[res])//给定元素个数<=8000且元素总和<=8000的数组
                      {
                          sum+=mp[res];
                          mp[res]=0;//只能加一次
                      }
                }
        }
        //cout<<sum<<endl;
        printf("%d\n",sum);
    }
    return 0;
}

F. Binary String Reconstruction

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e6+10,M=2023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
    	LL a,b,c;
    	cin>>a>>b>>c;
    	if(b==0)
    	{
    		if(a!=0)
    		{
    			for(int i=1;i<=a+1;i++)
    			{
    				cout<<"0";
				}
			}
			else if(c!=0)
			{
				for(int i=1;i<=c+1;i++)
				{
					cout<<"1";
				}
			}
			cout<<endl;
		}
		else
		{
			string ans="";
			if(b!=0)
			{
				for(int i=1;i<=b;i++)
				{
					if(i==1) ans+="10";
					else
					{
						if(i%2==0) ans+="1";
						else ans+="0";
					}
				}
			}
			string sum="";
			for(int i=0;i<ans.size();i++)
			{
				if(ans[i]=='1'&&c!=0)
				{
					for(int i=1;i<=c;i++)
					{
						sum+="1";
					}
					c=0;
				}
				else if(ans[i]=='0'&&a!=0)
				{
					for(int i=1;i<=a;i++)
					{
						sum+="0";
					}
					a=0;
				}
				sum+=ans[i];
			}
			cout<<sum<<endl;
		}
    }
    return 0;
}

G. Special Permutation

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=1e6+10,M=2023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
    	LL n;
		cin>>n;
		if(n==2||n==3) cout<<"-1"<<endl;
		else if(n==4) cout<<"3 1 4 2"<<endl;
		else if(n==5) cout<<"5 3 1 4 2"<<endl;
		else if(n==6) cout<<"5 3 6 2 4 1"<<endl;
		else if(n==7) cout<<"5 1 3 6 2 4 7"<<endl;
		else
		{
			deque<LL> dq;
			dq.push_back(5); dq.push_back(1); dq.push_back(3); 
			dq.push_back(6); dq.push_back(2); dq.push_back(4);
			dq.push_back(7);
			for(int i=8;i<=n;i++)
			{
				if(i%2==0) dq.push_front(i);
				else dq.push_back(i);
			}
			for(int i=0;i<dq.size();i++)
			{
				cout<<dq[i]<<" ";
			}
			cout<<endl;
			dq.clear();
		}
    }
    return 0;
}
posted @ 2023-04-05 16:40  Vijurria  阅读(7)  评论(0编辑  收藏  举报