AtCoder Grand Contest 018 A Getting Difference(比较水。。。)
来源:互联网 发布:java文件上传原理 编辑:程序博客网 时间:2024/06/07 00:50
http://agc018.contest.atcoder.jp/tasks/agc018_a
题意:给你N个数,每次取出两个数,再把他们差的绝对值连同这俩数扔进去,求能不能得到K。
题解:第一种情况,K膜这些数的GCD不为零是肯定做不到的,想一想就知道了嘛。。。第二种K大于最大的数也是做不到的,其他情况都可以做到。。。
//库省略using namespace std;int n,k;int a[100005];bool f,f2;int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b);}int main(){ cin>>n>>k; if(n==1) { int a; cin>>a; if(a==k) cout<<"POSSIBLE"; else cout<<"IMPOSSIBLE"; return 0; } int g=1; for(int i=0;i<n;i++) { cin>>a[i]; if(i==1) g=gcd(a[0],a[1]); else if(i>1) { int t=g; g=gcd(t,a[i]); } if(a[i]>=k) f=1; } if(!f || k%g!=0) { cout<<"IMPOSSIBLE"; } else { cout<<"POSSIBLE"; } return 0;}
阅读全文
0 0
- AtCoder Grand Contest 018 A Getting Difference(比较水。。。)
- AtCoder Grand Contest 018 --------- Getting Difference
- AtCoder Grand Contest 018 A
- atcoder grand Contest 018 A
- AtCoder Grand Contest 018 A
- AtCoder GC 018A: Getting Difference 题解
- AtCoder Grand Contest 018
- AtCoder Grand Contest 018
- AtCoder Grand Contest 012 A
- AtCoder Grand Contest 017-A
- AtCoder Grand Contest 018 E
- AtCoder Grand Contest 018 F
- 【AtCoder】 Grand Contest 018 C
- AtCoder Grand Contest 017-A Biscuits
- AtCoder Grand Contest 018--D题
- AtCoder Grand Contest 018 做题记录
- AtCoder Grand Contest 010
- AtCoder Grand Contest 011
- 链表翻转----逆置链表的变形
- 更纯粹的下拉刷新和加载更多
- caffe的相关配置
- Android RecyclerView 使用完全解析 体验艺术般的控件
- C++中汉字字符串的截取
- AtCoder Grand Contest 018 A Getting Difference(比较水。。。)
- 注册了博客,感觉自己就很帅~
- k-Means聚类算法实现--基于西瓜数据4.0
- ios 判断是iphone还是ipad
- java设计模式之代理模式
- Oracle创建序列
- iOS runTime运行时机制
- mysql-5.7.12-winx64安装的时候无法启动服务问题
- 双链表的创建、删除、插入及打印(数据结构)