nyoj1062
来源:互联网 发布:内网访问阿里云 编辑:程序博客网 时间:2024/06/06 06:32
题意:给你一个数列,你可以使数列的某一个数加上若干个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;}
0 0
- nyoj1062
- hql多表关联查询
- android studio将代码关联到git@osc(出现 Empty repository,以及push reject解决)
- 1017. A除以B (20)----string的额外操作
- 操作基本数据类型的流
- scrollview嵌套listview
- nyoj1062
- Android Studio 轻松打jar 包
- UVa 1594 Ducci Sequence
- Ubuntu16.04 用root身份登陆
- 内存操作流(处理临时信息)
- C#设计模式学习笔记(一) 之 简单工厂模式
- Android官方开发文档Training系列课程中文版:打印内容之图像打印
- 打印流的使用
- 【杭电oj】1556 - Color the ball(区间更新)