ACM POJ 2356
2013-08-08 09:59
176 查看
TimeLimit:1000MS
MemoryLimit:65536KB
64bitIOFormat:%I64d&%I64u
[
Description
TheinputcontainsNnatural(i.e.positiveinteger)numbers(N<=10000).Eachofthatnumbersisnotgreaterthan15000.Thisnumbersarenotnecessarilydifferent(soitmayhappenthattwoormoreofthemwillbeequal).Yourtaskistochooseafewofgivennumbers(1<=few<=N)sothatthesumofchosennumbersismultipleforN(i.e.N*k=(sumofchosennumbers)forsomenaturalnumberk).
Input
ThefirstlineoftheinputcontainsthesinglenumberN.EachofnextNlinescontainsonenumberfromthegivenset.
Output
Incaseyourprogramdecidesthatthetargetsetofnumberscannotbefounditshouldprinttotheoutputthesinglenumber0.Otherwiseitshouldprintthenumberofthechosennumbersinthefirstlinefollowedbythechosennumbersthemselves(onaseparatelineeach)inarbitraryorder.
Iftherearemorethanonesetofnumberswithrequiredpropertiesyoushouldprinttotheoutputonlyone(preferablyyourfavorite)ofthem.
SampleInput
5 1 2 3 4 1
SampleOutput
2 2 3
Source
抽屉原理,开始高明白,安叔一点拨就清楚了,Orz,和mod后相同的两个数就可以
给代码了
#include<cstdio>
[code]#include<cstring>
constintN=10001;
inta ,sum ,visit ;
intn;
voidprint(inti,intj)
{
printf("%d\n",j-i+1);
intk;
for(k=i;k<=j;k++)
{
printf("%d\n",a[k]);
}
return;
}
intmain()
{
scanf("%d",&n);
sum[0]=0;
memset(visit,0,sizeof(visit));
for(inti=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum[i]=(a[i]+sum[i-1])%n;
}
//for(inti=1;i<=n;i++)
//{
//printf("%d\n",sum[i]);
//}
for(inti=1;i<=n;i++)
{
if(sum[i]==0)
{
print(1,i);
return0;
}
else
{
if(visit[sum[i]]!=0)
{
print((visit[sum[i]]+1),i);
return0;
}
else
{
visit[sum[i]]=i;
//printf("%d\n",visit[i]);
}
}
}
}
[/code]
相关文章推荐
- 【ACM】poj_2356_Find a multiple_201308061947
- [ACM] POJ 3485 Highway (区间选点问题)
- 【鸽巢定理】POJ_2356
- [ACM] POJ 3096 Surprising Strings (map的使用)
- acm常用技巧三 POJ 3279
- ACM刷题之Poj————Wireless Network
- ACM POJ 3463 Sightseeing
- POJ 3436 ACM Computer Factory
- [ACM] POJ 1068 Parencodings(模拟)
- [ACM] poj 1088 滑雪 (记忆化搜索DFS)
- [ACM] POJ 2689 Prime Distance (大区间素数筛选)
- ACM-MST(最小生成树)之Agri-Net——poj1258
- acm解题报告 POJ 2366 Sacrament of the sum
- POJ 3436 ACM Computer Factory
- POJ ACM 1002
- ACM POJ 3264 Balanced Lineup(线段树)
- ACM HEU OJ 1019 Ferry Loading II || POJ 2336
- poj 3436 ACM Computer Factory
- POJ 2356 Find a multiple <抽屉原理>
- [ACM] poj 1496 Word Index(组合计数)