文章目录
时间:2020 03 26
传送门
这次比赛又做崩了,下次如果wa了的话,3分钟后在提交第二次
A - Sum of Odd Integers CodeForces - 1327A
题意:给出一个数n,问是否能分解为k个不相等的奇数
一开始就看错题了,到后面也崩了
做法:把n-=1,3,5…,在判断剩下的n是否大于f[k-1],且为奇数。
1,3,5直接等差数列求和
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e7;
int t,n,k;
ll ok[maxn];
int main(){
for(int i=1;i<=maxn;i++)
ok[i]=2*i-1;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
n-=pow(k-1,2);
if(n<=ok[k-1]){
cout<<"NO"<<endl;
continue;
}
if(n%2==0)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
B - Princesses and Princes CodeForces - 1327B
审好题,然后模拟即可
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int t,n;
bool ok1[maxn],ok2[maxn];
int main(){
scanf("%d",&t);
while(t--){
memset(ok1,false,sizeof(ok1));
memset(ok2,false,sizeof(ok2));
scanf("%d",&n);
for(int i=1;i<=n;i++){
int cnt,y;
scanf("%d",&cnt);
for(int j=1;j<=cnt;j++){
scanf("%d",&y);
if(!ok1[i]&&!ok2[y]){
ok1[i]=true;
ok2[y]=true;
}
}
}
bool flag=false,flag1=false;;
for(int i=1;i<=n;i++){
if(!ok1[i]){
flag=true;
cout<<"IMPROVE"<<endl;
printf("%d ",i);
break;
}
}
for(int i=1;i<=n;i++){
if(!ok2[i]){
printf("%d\n",i);
flag1=true;
break;
}
}
if(flag&&!flag1)cout<<1<<endl;
if(!flag)printf("OPTIMAL\n");
}
return 0;
}
C - Game with Chips CodeForces - 1327C
c题是真的思维了,题目中说可以不用最小步骤、并且几个芯片可以在同一单元这是关键。然后直接按照最右下角移动到左上角,然后绕着地图跑一边就行了。甚至不用记录芯片及该走到的点
#include<bits/stdc++.h>
using namespace std;
const int maxn=200+10;
int n,m,k;
int sum;
struct node{
int x,y;
}a[maxn],f[maxn];
string s;
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;i++)
scanf("%d%d",&a[i].x,&a[i].y);
for(int i=1;i<=k;i++)
scanf("%d%d",&f[i].x,&f[i].y);
for(int i=1;i<=n-1;i++)
s+="U",sum++;
for(int i=1;i<=m-1;i++)
s+="L",sum++;
for(int i=1;i<=n;i++){
if(i%2!=0){
for(int j=1;j<=m-1;j++)
s+="R",sum++;
}
else{
for(int j=1;j<=m-1;j++)
s+="L",sum++;
}
if(i!=n)
s+="D",sum++;
}
cout<<sum<<endl<<s<<endl;
}