Description

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求余是0。 通常大家会想把这些数随机组合,得到的和存放在一个数组里,但遇到很多数,这就不好办了。 由于问题只要找出一组即可,所以我们就是要找到一组。 所以我建立个抽屉模型,
为什么可以用抽屉模型?有n个数,这些数的连续和分别对n取余得到的余数范围是0~n-1, 不相同的余数个数不超过n,当个数为n时, 那其中肯定有一组数的和满足条件,若小于n,这当中至少有两组数的余数相同,举个
例子,1,3,5,9,2 ,5个数, 我把它们连续相加变成, 1,4, 9, 18, 20, 仍然是5个数。 使他们一一对5取余,得到 1, 4, 4, 3, 0。 我把余数当作抽屉,和作为物体, 这里有5个物体,4个抽屉,
第一组数是1,3,第二组数是1,3,5。 用后者减前者便是答案。
#include <stdio.h>
#define M 10001
int a[M], mod[M];
int main()
{
int n, i, sum, begin, end;
while(scanf("%d", &n) != EOF){ sum = ;
for(i = ; i <= n; i++){ scanf("%d", &a[i]); }
for(i = ; i <= n; i++){ sum = (sum + a[i]) % n;
if(!sum)
{
begin = ;
end = i;
break;
}
else if(mod[sum] > )
{
begin = mod[sum] + ;
end = i;
break;
}
mod[sum] = i; }
printf("%d\n", end - begin + );
for(i = begin; i <= end; i++){ printf("%d\n", a[i]); }
putchar('\n'); }
return ;
}

find a multiple的更多相关文章

  1. Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...

    Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  4. SharePoint "System.Data.SqlClient.SqlException (0x80131904): Parameter '@someColumn' was supplied multiple times.“

    最近在处理SharePoint Office365的相关开发的时候发现了这样一个奇怪的现象: 无法通过API更新Editor field,只要已更新就会throw Exception,由于是Offic ...

  5. 2012Chhengdu K - Yet Another Multiple Problem

    K - Yet Another Multiple Problem Time Limit:20000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher

    加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...

  7. scala - multiple overloaded alternatives of method bar define default arguments

    同名同位置默认参数不能overload def bar(i:Int,s:String="a"){} def bar(i:String,s:String="b") ...

  8. 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?

    复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...

  9. 多文档上传(upload multiple documents)功能不能使用怎么办?

    问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰 ...

  10. OPEN CASCADE Multiple Variable Function

    OPEN CASCADE Multiple Variable Function eryar@163.com Abstract. Multiple variable function with grad ...

随机推荐

  1. java多线程--实现Runnable接口

    package unit8; import java.applet.Applet; import java.awt.Label; import java.awt.TextField; public c ...

  2. node.js整理 06异步编程

    回调 异步编程依托于回调来实现,但不能说使用了回调后程序就异步化了 function heavyCompute(n, callback) { var count = 0, i, j; for (i = ...

  3. HTTP基础06--网络安全

    HTTP 的缺点 通信使用明文可能会被窃听 HTTP 报文使用明文(指未经过加密的报文)方式发送. 通信的加密 用 SSL 建立安全通信线路之后,就可以在这条线路上进行 HTTP 通信了.与 SSL ...

  4. BZOJ 2716 [Violet 3]天使玩偶 ——KD-Tree

    [题目分析] KD-Tree的例题.同BZOJ2648. [代码] #include <cstdio> #include <cstring> #include <cstd ...

  5. C#,往线程里传参数的方法总结

    Thread (ParameterizedThreadStart) 初始化 Thread 类的新实例,指定允许对象在线程启动时传递给线程的委托.   Thread (ThreadStart) 初始化 ...

  6. 快速搭建Webservice接口测试环境

    一.必备工具: apache-tomcat.Axis2(WebService引擎).实例类 二.部署步骤: 1.到apache官网 http://apache.org/ 下载apache-tomcat ...

  7. Oracle 中的游标(用Javase中Iterator 类比之)

    当使用 pl/sql 查询 Oracle 数据库时,有时我们想输出多条记录的数据.:select * from scott.emp; 这时,我们一定会想利用循环来输出.但是,在pl/sql 中是没有数 ...

  8. 目前quanben评十大哲学家

    排名分先后,包含时间.地区和主要正面成就以及其他代表人物. 1. 伊曼努尔·康德:十八世纪:东普鲁士:理性的界限,现象和本体分立以及主体的地位2. 柏拉图:公元前三四百年:古希腊:理想(念)世界3. ...

  9. Posterior visual bounds retrieval for the Plato framework

    Plato is a MVVM compliant 2D on-canvas graphics framework I've been designing and implementing for d ...

  10. Android annotations REST

    使用前: public class BookmarksToClipboardActivity extends Activity { BookmarkAdapter adapter; ListView ...