p2356_鴿籠原理!cool!

Find a multiple
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1895   Accepted: 813   Special Judge

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

Source


非常酷的一道題;
n個數中找出一些數可以整除n,就是找都某幾個數的和對n取餘得0;
設s[k]是前k的和,那麼在所有n個s中,必定有一個爲0 或者存在兩個相等。
這就應用了傳說中的鴿籠原理。因爲對n取餘的結果是0---n-1放在n個s中,至少有兩個相等,那麼相等的位置之間的和對n取餘的結果一定是0。

後記:很酷吧!不知道是誰想出來的。。
前幾天剛看過鴿籠原理,覺得確實很好玩,但是碰到這道題後就是沒有想到,有些信息確實很有用的,首先n很大對不,n^2肯定不行;第二爲什麼非要等於n呢,您說呢~,數學這東東很有意思!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章