The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000. This numbers are not necessarily different (so it may happen that two or more of them will be equal). Your task is to choose a few of given numbers ( 1 <= few <= N ) so that the sum of chosen numbers is multiple for N (i.e. N * k = (sum of chosen numbers) for some natural number k).

Input

The first line of the input contains the single number N. Each of next N lines contains one number from the given set.

Output

In case your program decides that the target set of numbers can not be found it should print to the output the single number 0. Otherwise it should print the number of the chosen numbers in the first line followed by the chosen numbers themselves (on a separate line each) in arbitrary order. 

If there are more than one set of numbers with required properties you should print to the output only one (preferably your favorite) of them.

Sample Input

5
1
2
3
4
1

Sample Output

2
2
3

题意:

输入n

输入n个数

判断这n个数中是不是有几个数字之和是n的倍数

思路:

n个数余数分别为 1 ~ n-1 ,相当于有n-1个抽屉,n个物品

分别计算a[1] + a[2] + …… + a[k] 的和然后取余如果为零则直接输出前k个数,否则寻找余数相同的两个数,假设为i, j (i < j),则a[i+1] + . . . . + a[j] 的和一定能被n整除(原理还没想清楚)

AC代码

 1 #include<iostream>
2 #include<stdio.h>
3 #include<string.h>
4 using namespace std;
5 int a[10005];
6 int mod[10005];
7 int mark[10005];
8
9 int main()
10 {
11 int n;
12 bool flag = false;
13 cin >> n;
14 memset(mod, 0, sizeof(mod));
15 memset(mark, 0, sizeof(mark));
16 for(int i = 1; i <= n; i++)
17 {
18 cin >> a[i];
19 mod[i] = (mod[i-1] + a[i]) % n;
20 }
21
22 for(int i = 1; i <= n; i++)
23 {
24 if(mod[i] == 0)
25 {
26 flag = true;
27 cout << i << endl;
28 for(int j = 1; j <= i; j++)
29 cout << a[j] << endl;
30 break;
31 }
32 }
33
34 if(!flag)
35 {
36 for(int i = 1; i <= n; i++)
37 {
38 if(mark[mod[i]] == 0)
39 mark[mod[i]] = i;
40 else
41 {
42 cout << i -mark[mod[i]] << endl;
43 for(int j = mark[mod[i]]+1; j <= i; j++)
44 cout << a[j] << endl;
45
46 break;
47 }
48 }
49 }
50
51 return 0;
52 }

最新文章

  1. ZOJ Light Bulb - 3203
  2. 高性能PHP日志插件--Seaslog
  3. QTableView使用HTML显示富文本
  4. hadoop系列一:hadoop集群安装
  5. ABP框架 - N层架构
  6. java中hashCode()与equals()详解
  7. 解决React首屏加载白屏的问题
  8. sed常见用法总结
  9. C#/Net定时导出Excel并定时发送到邮箱
  10. VS2010自行编译OpenCV2.4.4时缺少python27_d.lib的解决方法
  11. 洛谷 P5162 WD与积木 解题报告
  12. 架构-LAMP特级学习(网站服务器监控)
  13. Lucene.Net(转)
  14. 在Linux中监视IO性能
  15. Python map/reduce/filter/sorted函数以及匿名函数
  16. 使用公共的存储过程实现repeater的分页
  17. nginx 隐藏index.php 并开启rewrite日志调试(apache也有)
  18. R语言网络爬虫学习 基于rvest包
  19. 51 nod 1522 上下序列——序列dp
  20. codechef FUN WITH TREES

热门文章

  1. Python 过滤字母和数字
  2. 【ZeyFraのJavaEE开发小知识02】MybatisPlus&amp;ElementUI
  3. go 报错 import cycle not allowed
  4. 腾讯云容器服务 TKE 拿下新加坡 MTCS 最高级别安全认证
  5. CentOS7 安装 MySQL Cluster 7.6.7
  6. 解决 Ant Design Modal 中的 Select 选项框不能显示的问题
  7. 爬虫必知必会(6)_提升scrapy框架爬取数据的效率之配置篇
  8. js 判断 是否在当前页面
  9. javascript 最权威的知识点总结
  10. codefoces D. Phoenix and Science