您的位置:首页 > 其它

nyoj1062

2016-05-02 14:19 260 查看
题意:给你一个数列,你可以使数列的某一个数加上若干个k,使最后这个长度为n的数列的数为1-n且每个数只出现一次。

思路:模拟。

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=105;
int a[maxn];

int main(){
// freopen("51.txt","r",stdin);
int n,k;
while(scanf("%d%d",&n,&k)!=EOF){
int x;
memset(a,0,sizeof(a));
for(int i=1; i<=n; i++){
scanf("%d",&x); a[x]++;
}
int f=0;
for(int i=1; i<=n; i++){
while(a[i]>1){
int c=0;
int kk=i+k;
while(kk<=n){
if(!a[kk]){
c=1;
a[kk]++;
break;
}
kk=kk+k;
}
if(c==0){
break;
}
a[i]--;
}
}
for(int i=1; i<=n; i++){
if(!a[i] || a[i]>1) f=1;
}
if(f) printf("IMPOSSIBLE\n");
else printf("POSSIBLE\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: