Find a multiple
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6535   Accepted: 2849   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

Ural Collegiate Programming Contest 1999
 
鸽巢定理,注意代码实现的细节,0MS ac
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 10010 struct Node
{
int x,y,s; //下标,余数,前缀和
bool operator <(const Node &t)const
{
if(y!=t.y) return y<t.y;
return x<t.x;
}
}p[N]; int main()
{
int n;
int flag;
int a[N];
while(scanf("%d",&n)!=EOF)
{
flag=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
p[i].s=p[i-].s+a[i];
p[i].x=i;
p[i].y=p[i].s%n;
if(!flag && p[i].y==)
{
flag=;
printf("%d\n",i);
for(int j=;j<=i;j++) printf("%d\n",a[j]);
}
}
if(flag) continue;
sort(p+,p+n+);
for(int i=;i<=n;i++)
{
if(p[i].y==p[i-].y)
{
int &l=p[i-].x;
int &r=p[i].x;
printf("%d\n",r-l);
for(int j=l+;j<=r;j++) printf("%d\n",a[j]);
break;
}
}
}
return ;
}

[POJ 2356] Find a multiple的更多相关文章

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

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

  2. POJ 2356 Find a multiple 抽屉原理

    从POJ 2356来体会抽屉原理的妙用= =! 题意: 给你一个n,然后给你n个数,让你输出一个数或者多个数,让这些数的和能够组成n: 先输出一个数,代表有多少个数的和,然后再输出这些数: 题解: 首 ...

  3. poj 2356 Find a multiple(鸽巢原理)

    Description The input contains N natural (i.e. positive integer) numbers ( N <= ). Each of that n ...

  4. poj 2356 Find a multiple【鸽巢原理 模板应用】

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6651   Accepted: 2910   ...

  5. POJ 2356 Find a multiple( 鸽巢定理简单题 )

    链接:传送门 题意:题意与3370类似 注意:注意输出就ok,输出的是集合的值不是集合下标 /***************************************************** ...

  6. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  7. POJ 1426 Find The Multiple --- BFS || DFS

    POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...

  8. POJ 1426 Find The Multiple(寻找倍数)

    POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given ...

  9. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

随机推荐

  1. console.log的使用

    相比alert他的优点是: 他能看到结构话的东西,如果是alert,淡出一个对象就是[object object],但是console能看到对象的内容. console不会打断你页面的操作,如果用al ...

  2. 十六、mysql 分区之 简单sql优化1

    .使用 show session status like '%Com_%'; 可以查看当前连接的各个sql的执行频率 show global status like '%Com_%'; 可以查看从上次 ...

  3. 让用户打开你app的位置功能

    +运动 http://www.ccidnet.com/2015/0819/10014152.shtml 让你的app不再是一个购物网站, 而是一种生活方式, 逛街,在实体店逛街积累里程,兑换积分  送 ...

  4. 手写归并排序(MergeSort)

    #include<iostream> #include<stdio.h> #include<algorithm> #define N 10000 using nam ...

  5. Hibernate注解方法使用总结

    1.类级别注解 @Entity     映射实体类 @Table    映射数句库表 @Entity(name="tableName") - 必须,注解将一个类声明为一个实体bea ...

  6. js中批量处理样式——cssText的使用

    http://www.cnblogs.com/snandy/archive/2011/03/12/1980444.html

  7. ural 1069

    题意:删除一棵树上的叶子 每删除一片叶子就写下连着该片叶子的节点  让你还原一棵树 记录每个节点连着的叶子数 0表示此时这个节点就是叶子  -1表示这个节点已经删除 删除的只能是0  就是说是叶子 暴 ...

  8. DJANGO输出HIGHCHARTS数据的样例

    XXX,DJANGO ORM里确实有很深的水,需要慢慢理解.. 比如: 获取指定时间段的数据: app.deployversion_set.filter(add_date__range=(date_s ...

  9. 关于DJANGO和JAVASCRIPT的时间

    最近,实际一些简单统计时,要到库里去检索数据出来用HIGHCHARTS画图, 作一个简单的回照.. DJANGO用TEMPLATEVIEW来作.专业,正规:) class SAView(Templat ...

  10. lsof命令总结

    1.lsof 简介 lsof 是 linux 下的一个非常实用的系统级的监控.诊断工具.它的意思是 List Open Files,很容易你就记住了它是 “ls + of”的组合~它可以用来列出被各种 ...