首页 > 其他分享 >Codeforces Round 640 (Div. 4) ABCDEFG

Codeforces Round 640 (Div. 4) ABCDEFG

时间:2023-04-05 16:59:07浏览次数:55  
标签:typedef const int LL cin long 640 ABCDEFG Div

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;
}

标签:typedef,const,int,LL,cin,long,640,ABCDEFG,Div
From: https://www.cnblogs.com/Vivian-0918/p/17289088.html

相关文章

  • Codeforces Round 863 (Div. 3) A-C 赛后思路复盘
    A(思维)思路:观察样例可知数越大放在前面越优。遍历字符串,判断当前位置的数字和要插入的数字的关系,如果要插入的数大于当前数,那么就插入到当前数的前面。string里有一个insert函数,可以把指定字符串插入到指定下标之前。在原串下标为pos的字符前插入字符串strbasic_string&insert......
  • cf-div.3-863d
    题目链接:https://codeforces.com/contest/1811/problem/D思维题,昨天被E题搞太久了,这题认真想的话应该可以出的。思路:不断循环,判断x和y是否在合法区间内。代码:#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;longlongfib[70];voidsolve(){int......
  • Codeforces Round 861 (Div. 2)
    Preface这场感觉都是一个礼拜前补题打的了,但由于上周末事情比较多都没来得及写题解因此可能题意都记得不是很清楚了,就简略地谈一谈吧A.LuckyNumbers不难想到直接暴力从左端点枚举到右端点并对每个数进行暴力判断一个很naive的结论就是当答案为\(9\)时直接输出即可,然后我们......
  • Codeforces Round 717 (Div. 2) B. AGAGA XOOORRR(位运算)
    https://codeforces.com/contest/1516/problem/B题目大意:给定长度为n的数组a,问我们能不能一直选择两个相邻的元素进行异或后,删除这两个值,把异或值留下来,最后剩下>=2个数字,它们都是相同的?可以做到输出YES,不能的话输出NO。input23022423110outputYESNO题......
  • CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)-C
    参考了佬的c题题解思路,感觉很巧妙,记录一下https://zhuanlan.zhihu.com/p/618685370#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=2*100010;inta[N];voidsolve(){ intn,c,d; cin>>n>>c>>d; set<int>se......
  • Multimedia (MP3, MPEG-4, AVI, DiVX, etc.) support in Ubuntu 12.04 (Precise)
    Whydoesn’tUbuntusupportMP3‘outofthebox’?UbuntucannotincludesupportforMP3orDVDvideoplaybackorrecording.MP3formatsarepatented,andthepatentholdershavenotprovidedthenecessarylicenses.Ubuntualsoexcludesothermultimediasof......
  • cf-div.2-862d
    题目链接:https://codeforces.com/contest/1805/problem/D赛时没过的题。思路:首先发现一个性质:对于k来说,如果树上的一个点到树的直径的两个端点的距离都小于k的话,那么这个点一定是一个孤立点。证明:采用反证法:假设\(x,y\)为树的直径的两个端点,\(a,b\)为另外两个点,且有\(d[a][x]<k......
  • Codeforces Round 862 (Div. 2) A-D题解
    比赛地址A.WeNeedtheZero题意:给出一个数组,对任意1<=i<=n,令bi=aix,问是否存在x,使得b<sub>1</sub>b2...bn=0Solution如果n为奇数,那么x一定存在,因为偶数个x异或得到的是0,直接令x=0(a<sub>1</sub>a2...an)即可如果n为偶数,那么x取任何值都不会影响结果,所以只用看a1a<sub>2</sub......
  • Codeforces Round 862 (Div. 2) (4.2)
    CodeforcesRound862(Div.2)A-WeNeedtheZero思路:某个数被异或两次相当于没变,即判断n的奇偶性;n为偶数时判断所有数异或后的数是否为0,若为0,输出任意数;n为奇数时答案为所有数异或后的值#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;consti......
  • Codeforces Round 862 (Div. 2)A-C思路复盘
    感觉这场前三题都简单,复盘一下赛时的脑回路QAQ,c二分wa了四发赛后才过的血亏A题意:问是否能找到一个数x,有\(b_i=a_i⊕x\),使得\(b\)数组的总异或和为0。思路:赛时模拟样例可以发现先把a数组的总异或和求出来假设为x,然后由异或性质可知相同为0,不同为1,可知这个x可能就是答案。然......