UESTC 1014 The King and King boss 鸽巢原理
2015-11-30 22:54
399 查看
The King and King boss
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Submit
Status
王和王老板总是在向大家传授什么是美。今天,王老板要为趣味赛出题,他想出了一个很美的问题:“给你一个包含n个元素的整数集合a1⋯an,
问你是否可以找到它的一个子集,使得这个子集的和可以被n整除”
听到了这个问题后,王暗想“这是个非常简单的问题,我可以设计一个动态规划算法在线性时间复杂度内轻松解决”,但他口头上依然称赞这是个非常好
的问题。当然,王不打算亲自解决(这题太水啦!),他用不容拒绝的口吻命令你完成它。
Input
第一行是整数集合的大小n(1≤n≤10000)第二行包含n个整数a1⋯an,且每个数都小于10000(ai≤10000)
Output
如果存在上述的一个子集,输出Yes,否则输出
No(注意大小写)。
例子:如果给你三个数的集合{2,4,4
},你可以非常轻松地看出,子集{2,4
}的和为6可以被3 整除,所以会毫不犹豫地输出
Yes。
Sample input and output
Sample Input | Sample Output |
---|---|
3 2 4 4 | Yes |
My Solution
这个题目主要是自己分析吧,看下题目的数量级和答案的格式,是在叫我们好好分析了(x1) mod n
(x1+x2) mod n
(x1+x2+x3) mod n
(...... ...... ......) mod n
(x1+x2+x3+x4+......xn) mod n
1) 当上面的n个数各不相等是,显然Yes;
2)当至少有两个是相等的时候,比如{x1,......x j } 、 {x1,......x i } 设 j > i ;
则前者减后者得 {x i+1,......x j } 其值为0,(0 % n) ==0 显然Yes
综上 必为 Yes
#include <iostream> #include <string> #include <cstdio> int main() { int n; scanf("%d",&n); std::string str; getchar(); getline(std::cin,str); printf("Yes"); return 0; }
或者
#include <iostream> #include <cstdio> using namespace std; const int maxn=10000+8; int A[maxn]; int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&A[i]); printf("Yes"); return 0; }
谢谢
相关文章推荐
- 从头认识java-11.2 "+"与StringBuilder
- 黑马程序员_javaGUI综合部件布局与事件处理
- Masonry + UIView Animations 注意事项
- Duilib源码分析(四)绘制管理器—CPaintManagerUI
- 理解 Android Build 系统
- 【LEETCODE】62-Unique Paths
- 快速排序--quickSort
- UICollectionView
- 容器总结——array、vector、deque
- 动态修改UINavigationBar的背景色
- description The resource identified by this request is only capable of generating responses with cha
- UI(一)
- request与response
- easy-ui 小白进阶史(二):操作数据,easy-ui操作
- ui 霓虹灯
- StringBuffer和StringBuilder
- IOS开发之UIview
- UIButton 的一些属性
- 奇怪的现象:touchesBegan: 与UITapGestureRecognizer手势没有人响应 以及set方法的妙用
- 在Visual Studio中使用VueJS时,不可以用 v-bind 的简写 : 及 v-on的简写 @