poj 2356鸽笼原理水题
关于鸽笼原理的知识看我写的另一篇博客
http://blog.csdn.net/u011026968/article/details/11564841
(需要说明的是,我写的代码在有答案时就输出结果了,但OJ也是从文件读入,所以乍一看我的好像在没输入完就有结果了,但OJ不知道,其实我是直接拿poj3370的代码AC的,32MS,O(∩_∩)O)
直接贴代码
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100002 int sum[N],pos[N],a[N]; int main()
{ int n,i,r,t,j; while(~scanf("%d",&n))
{
memset(pos,-1,sizeof(pos));
bool flag=false; scanf("%d",&sum[0]);
a[0]=sum[0];
sum[0]%=n;
pos[sum[0]]=0;
if(sum[0]==0)
{
printf("1\n%d\n",sum[0]);
flag=1;
} for(i=1;i<n;i++)
{
scanf("%d",&sum[i]);
if(flag)continue;
a[i]=sum[i];
sum[i]%=n;
sum[i]+=sum[i-1];
sum[i]%=n;
if(sum[i]==0)
{
printf("%d\n",i+1);
for(j=0;j<=i;j++)
printf("%d\n",a[j]);
flag=1;
continue;
}
if(pos[sum[i]]==-1)pos[sum[i]]=i;
else
{
printf("%d\n",i-pos[sum[i]]);
for(j=pos[sum[i]]+1;j<=i;j++)
printf("%d\n",a[j]);
flag=1;
}
} } return 0;
}
poj 2356鸽笼原理水题的更多相关文章
- POJ 1488 Tex Quotes --- 水题
POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...
- poj 3370 鸽笼原理知识小结
中学就听说过抽屉原理,可惜一直没机会见识,现在这题有鸽笼原理的结论,但其实知不知道鸽笼原理都可以做 先总结一下鸽笼原理: 有n+1件或n+1件以上的物品要放到n个抽屉中,那么至少有一个抽屉里有两个或两 ...
- POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- poj 2105 IP Address(水题)
一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...
- poj 2000 Gold Coins(水题)
一.Description The king pays his loyal knight in gold coins. On the first day of his service, the kni ...
- POJ 3673 Cow Multiplication (水题)
题意:给你两个数,求所有的数位的积的和. 析:太水了,没的说,可以先输入边算,也可以最后再算,一样.. 代码如下: #include <cstdio> #include <strin ...
随机推荐
- HDU 2138 How many prime numbers
米勒罗宾素数测试: /* if n < 1,373,653, it is enough to test a = 2 and 3. if n < 9,080,191, it is enoug ...
- Oracle select into from 和 insert into select
select into from SQLSERVER 创建表: select * into aaa from bbb Oracle 创建表: create table aaa as select * ...
- 禁止apache显示目录索引
1)修改目录配置: 复制代码 代码如下: <Directory "D:/Apache/blog.phpha.com">Options Indexes FollowSym ...
- 获取WebView里的网页文本内容
获取WebView里的网页文本内容,能够採用例如以下方法: public class ComJSInterface { public void loadHtmlContent(String conte ...
- config -导航
在config进行中配置 1在config中添加SITmap <siteMap enabled="true" defaultProvider="UserSiteM ...
- C# Best Practices - Specify Clear Method Parameters
Improve parameters parameter order public OperationResult PlaceOrder(Product product, int quantity, ...
- Value Categories
Value categories Three primary categories primary categories mixed special Each C++ expression (an o ...
- php基本框架
- 深入select_related与prefetch_related函数
阅读博客http://blog.jobbole.com/74881/的笔记 在数据库有外键的时候,使用select_related()和prefetch_related()可以很好的减少数据库请求的次 ...
- django cbv
django 提供了一系列现成的类视图,他们都继承自一个 View 基类(django.views.generic.base.View).在这个基类里实现了与 URLs 的接口(as_view).请求 ...