当前位置:网站首页>Codeforces Round #717 (Div. 2)
Codeforces Round #717 (Div. 2)
2022-06-27 22:03:00 【My story was traded for wine】
2021.4.21
A
The question : Give two numbers n and k, Then enter with n Sequence of Numbers , Each time the sequence is operated : Take two numbers , One of them plus 1, Another minus 1, And ensure that every number in the sequence is non negative . The sequence can be processed at most k operations , Make the sequence form a minimum dictionary order .( The two numbers taken from the title need to be different in size , always wa, As a result, the scene blew up ,)
Answer key : Each operation is for the first non 0 Number of numbers -1, Last number +1, Conduct k operations , If the sequence is all but the last number 0, Then you can exit the operation directly , The maximum dictionary order has been reached .
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int t,n,k,a[105];
cin>>t;
while(t--)
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
int l=1,r=n;
while(k)
{
if(a[l]>=k)
{
a[r]+=k;
a[l]-=k;
k=0;
}
else
{
a[n]+=a[l];
k-=a[l];
a[l]=0;
l++;
}
if(l==r)
break;
}
for(int i=1;i<=n;i++)
cout<<a[i]<<' ';
cout<<endl;
}
return 0;
}
B
The question : Give a number n, And then there's one that contains n Sequence of Numbers , You can XOR and sum two adjacent numbers ( At that time, it is regarded as bitwise OR ┭┮﹏┭┮), Then the length of the sequence is -1, Because two numbers XOR into a number . Finally, judge whether the changed sequence can become a sequence with the same number , It is required that the length of the last generated sequence meeting the conditions is at least 2.
Answer key :①x^x=0 ②x^x^x=x
First find the exclusive or sum of the whole sequence , If 0, according to ① The resulting sequence can be divided into exclusive or and equal sequences , If not 0, according to ③ Before traversal k(k<n) Whether the exclusive or sum of numbers is equal to the exclusive or sum of the whole sequence , If equal to, judge ((k+1) To (n-1)) Does the prefix XOR and have an equal to 0, If so, the whole sequence can be directly divided into XOR and equal three segment sequences .
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll t,n,a[2005];
cin>>t;
while(t--)
{
cin>>n;
a[0]=0;
int p=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]^=a[i-1];
}
if(a[n]==0)
{
cout<<"YES"<<endl;
continue;
}
int flag=1;
for(int i=1;i<n;i++)
{
if(a[i]==a[n])
{
for(int j=i+1;j<n;j++)
{
if(!a[j])
{
cout<<"YES"<<endl;
flag=0;
break;
}
}
}
if(!flag)
break;
}
if(flag)
cout<<"NO"<<endl;
}
}C
The question : Give a length of n Sequence , Judge whether this sequence can be divided into two groups of equal sequences , If you can , You need to delete at least a few numbers from the sequence to make the sequence ineligible , And list the subscripts of the deleted numbers .
Answer key : First, calculate the greatest common factor of the whole sequence , Then each number in the sequence is divided by the greatest common factor , Narrow the scope of , The resulting sequence must have odd numbers , And the result is the same as the original sequence
① Sequence sum is odd , It must not be possible to divide into two groups and equal sequences , Need to delete 0 A digital .
② Sequence sum is even but sequence sum /2 The resulting number cannot be determined by this n Sequences are randomly combined and added to get , It can't be divided into two groups and equal sequences , Need to delete 0 A digital .
③ Sequence sum is even , Just delete an odd number in the sequence to make the sequence sum odd , Then get ①
#include <bits/stdc++.h>
int dp[200005],a[105];
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
int n,d,sum=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i==1)
d=a[i];
else
d=gcd(d,a[i]);
}
for(int i=1;i<=n;i++){
a[i]/=d;
sum+=a[i];
}
int k=0;
dp[0]=1;
for(int i=1;i<=n;i++)
{
if(a[i]%2)
k=i;
for(int j=sum;j>=a[i];j--)
{
dp[j]|=dp[j-a[i]];
}
}
if(sum%2||!dp[sum/2])
cout<<0<<endl;
else
cout<<1<<endl<<k<<endl;
return 0;
}---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
No one left after the fight ......

边栏推荐
- Management system itclub (Part 2)
- 读写分离-Mysql的主从复制
- [LeetCode]动态规划解分割数组I[Red Fox]
- Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
- Professor of Tsinghua University: software testing has gone into a misunderstanding - "code is necessary"
- Example of using gbase 8A OLAP function group by grouping sets
- "Apprendre cette image" apparaît sur le Bureau win11 comment supprimer
- 软件测试自动化测试之——接口测试从入门到精通,每天学习一点点
- [LeetCode]508. 出现次数最多的子树元素和
- QT base64 encryption and decryption
猜你喜欢

Go from introduction to actual combat - execute only once (note)

Go from introduction to actual combat -- channel closing and broadcasting (notes)

Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear

Management system itclub (Part 2)

洛谷P5706 再分肥宅水

Figure countdownlatch and cyclicbarrier based on AQS queue

Burp suite遇到的常见问题

使用Jmeter进行性能测试的这套步骤,涨薪2次,升职一次

At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
![\W and [a-za-z0-9_], \Are D and [0-9] equivalent?](/img/96/2649c9cf95b06887b57fd8af2d41c2.png)
\W and [a-za-z0-9_], \Are D and [0-9] equivalent?
随机推荐
Magic POI error in reading excel template file
[sword offer ii] sword finger offer II 029 Sorted circular linked list
Use Fiddler to simulate weak network test (2g/3g)
[LeetCode]508. 出現次數最多的子樹元素和
真香,自从用了Charles,Fiddler已经被我彻底卸载了
[LeetCode]508. 出现次数最多的子树元素和
[LeetCode]30. 串联所有单词的子串
Simulink导出FMU模型文件方法
Stm32cubeide1.9.0\stm32cubemx 6.5 f429igt6 plus lan8720a, configure eth+lwip
AQS SOS AQS with me
How many ways does selenium upload files? I don't believe you have me all!
[LeetCode]161. 相隔为 1 的编辑距离
CDH集群之YARN性能调优
How to do function test well? Are you sure you don't want to know?
【MySQL】数据库函数通关教程下篇(窗口函数专题)
洛谷P5706 再分肥宅水
GBase 8a OLAP分析函数cume_dist的使用样例
win11桌面出现“了解此图片”如何删除
Process control task
Golang uses regularity to match substring functions