CF#658 d2 A-D
A:送的。这题因为有致命失误被hack了,血亏
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
int a[1002],b[1002],add,m,n,x;
cin>>t;
while(t--)
{
for(add=0;add<1002;add++)
{
a[add]=0;
b[add]=0;
}
cin>>m>>n;
for(add=0;add<m;add++)
{
cin>>x;
a[x]++;
}
for(add=0;add<n;add++)
{
cin>>x;
b[x]++;
}
for(add=0;add<1002;add++)
{
if(a[add]==b[add]&&a[add]!=0)
break;
}
if(add!=1002)
{
cout<<"YES"<<endl<<1<<" "<<add<<endl;
}
else
cout<<"NO"<<endl;
}
return 0;
} B:基本送的。统计第一个非1出现位置
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t,n,add,flag,x,q;
cin>>t;
while(t--)
{
cin>>n;
flag=0;
for(add=1;add<=n;add++)
{
cin>>x;
if(x!=1)
{
if(flag==0)
q=add;
flag=1;
}
}
if(!flag)
{
if(n%2)
cout<<"First"<<endl;
else
cout<<"Second"<<endl;
}
else
{
if(q%2)
cout<<"First"<<endl;
else
cout<<"Second"<<endl;
}
}
}C:基本送的。调整第一位,从后往前执行。
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t,n,p[1002],q[1002],add,add2,step,steps[3006];
char c;
cin>>t;
while(t--)
{
cin>>n;
step=0;
c=getchar();
for(add=1;add<=n;add++)
{
c=getchar();
p[add]=c-'0';
}
c=getchar();
for(add=1;add<=n;add++)
{
c=getchar();
q[add]=c-'0';
}
for(add=n;add>=1;add--)
{
if(p[1]==q[add])
{
step++;
steps[step]=1;
p[1]=1-p[1];
}
step++;
steps[step]=add;
for(add2=1;add2<=add;add2++)
p[add2]=1-p[add2];
for(add2=1;add2<=add/2;add2++)
{
if(p[add2]!=p[add+1-add2])
{
p[add2]=1-p[add2];
p[add+1-add2]=1-p[add+1-add2];
}
}
}
cout<<step<<" ";
for(add=1;add<=step;add++)
cout<<steps[add]<<" ";
cout<<endl;
}
return 0;
}D:稍有难度。在C的基础上,找到每一次第一位对应的原来的位置即可。
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int t,n,p[100002],q[100002],add,add2,step,steps[300006],s,sum,j[100002],x;
int main()
{
char c;
cin>>t;
while(t--)
{
cin>>n;
sum=0;
step=0;
c=getchar();
for(add=1;add<=n;add++)
{
c=getchar();
p[add]=c-'0';
}
c=getchar();
for(add=1;add<=n;add++)
{
c=getchar();
q[add]=c-'0';
}
add2=1;
for(add=n;add>0;add-=2)
{
j[add]=add2++;
}
add2=n;
for(add=n-1;add>0;add-=2)
{
j[add]=add2--;
}
for(add=n;add>=1;add--)
{
x=(p[j[add]]+n-add)%2;
if(x==q[add])
{
step++;
steps[step]=1;
}
step++;
steps[step]=add;
}
cout<<step<<" ";
for(add=1;add<=step;add++)
cout<<steps[add]<<" ";
cout<<endl;
}
return 0;
}E:dp没学好不会写子集合加总问题,血亏。自己写的dfs,直接tle了。
