nyoj1062
2016-05-02 14:19
260 查看
题意:给你一个数列,你可以使数列的某一个数加上若干个k,使最后这个长度为n的数列的数为1-n且每个数只出现一次。
思路:模拟。
AC代码:
思路:模拟。
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; }
相关文章推荐
- 关于Git的使用
- animation - 7
- hql多表关联查询
- Cocos2dx - Scheduler学习理解
- 【杭电-oj】-2073-无限的路(看起来很吓人的数学,开始都不敢做的)
- android studio将代码关联到git@osc(出现 Empty repository,以及push reject解决)
- [编译原理]学习笔记(一)——编译概述
- 平衡搜索树-AVL树
- openstack晋级攻略
- openstack晋级攻略
- Android常见问题总结(三)
- leetcode-62. Unique Paths
- 使用PS为Unity游戏创建简单的游戏素材实例
- 剑指offer 面试题(1)
- 彻底解决显示Opencv中Mat图像到Mfc窗口问题
- 学习进度表 08
- 欢迎使用CSDN-markdown编辑器
- Redis命令-集合-sinterstore
- 奶牛家族
- jQuery UI型插件