HDU 1808 Halloween treats
Your job is to help the children and present a solution.
InputThe input contains several test cases.
The first line of each test case contains two integers c and n (1 ≤ c ≤ n ≤ 100000), the number of children and the number of neighbours, respectively. The next line contains n space separated integers a 1 , ... , a n (1 ≤ a i ≤ 100000 ), where a i represents the number of sweets the children get if they visit neighbour i.
The last test case is followed by two zeros.
OutputFor each test case output one line with the indices of the neighbours the children should select (here, index i corresponds to neighbour i who gives a total number of a i sweets). If there is no solution where each child gets at least one sweet, print "no sweets" instead. Note that if there are several solutions where each child gets at least one sweet, you may print any of them.
Sample Input
4 5
1 2 3 7 5
3 6
7 11 2 5 13 17
0 0
Sample Output
3 5
2 3 4
题解: 鸽巢原理
参考代码:
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e5+;
int c,n,a[maxn],temp[maxn];
int main()
{
while(~scanf("%d%d",&c,&n),c+n)
{
for(int i=;i<=n;i++) scanf("%d",a+i),temp[i]=;
int sum=;
for(int i=;i<=n;i++)
{
sum=(sum+a[i])%c;
if(sum==)
{
for(int j=;j<i;j++) printf("%d ",j);
printf("%d\n",i);
break;
}
else if(temp[sum])
{
for(int j=temp[sum]+;j<i;j++) printf("%d ",j);
printf("%d\n",i);
break;
}
else temp[sum]=i;
}
}
return ;
}
HDU 1808 Halloween treats的更多相关文章
- HDU 1808 Halloween treats(抽屉原理)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1808 Problem Description Every year there is the same ...
- Halloween treats HDU 1808 鸽巢(抽屉)原理
Halloween treats Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- [POJ 3370] Halloween treats
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7143 Accepted: 2641 ...
- UVA 11237 - Halloween treats(鸽笼原理)
11237 - Halloween treats option=com_onlinejudge&Itemid=8&page=show_problem&category=516& ...
- POJ2270&&Hdu1808 Halloween treats 2017-06-29 14:29 40人阅读 评论(0) 收藏
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8565 Accepted: 3111 ...
- [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)
[POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...
- uva 11237 - Halloween treats(抽屉原理)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/37612503 题目链接:uva 11237 ...
- POJ 3370 Halloween treats(抽屉原理)
Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...
随机推荐
- IO类
Java的IO体系分为Input/Output和Reader/Writer两类,区别在于Reader/Writer在读写文本时能自动转换内码.基本上,所有的IO类多是配对的,即有XXXInput,就有 ...
- C++中对C的扩展学习新增语法——函数重载
函数重载 1.函数重载语法 1.同一个作用域(全局作用域.命名空间作用域.类作用域) 2.参数个数不同 3.参数类型不同 4.参数顺序不同 代码实现: 当函数名字一样的时候,通过参数类型.参数个数.参 ...
- C#查看已下载文件大小和扩展名
FileInfo fi = new FileInfo(fullfile);//fullfile文件路径 ong Size = fi.Length;//查看已下载文件的大小 C# 获取文件名及扩展名 s ...
- 小白学 Python 爬虫(1):开篇
人生苦短,我用 Python 引言 各位同学大家好,好久不见(可能只有一两天没见:囧)~~~ 先讲一件事情,昨天为啥没更新. emmmmmmmmm,当然是因为加班啦,快到年底了,公司项目比较忙,最近的 ...
- thinkphp在模板中使用php的函数
thinkphp在模板中使用php的函数 使用 {:函数名} 的形式 例如: // 获取 session 中存的值 {:session('admin.loginname')} // 输出当前日期 {: ...
- ReentreantLock:重入锁
ReentreantLock:重入锁 参考:https://www.cnblogs.com/nullzx/p/4968674.html 一). ReentrantLock与synchronized的区 ...
- 【Luogu P2024&P1892】食物链&团伙(并查集拓展域)
Luogu P1892 Luogu P2024 这两道一眼看过去很容易发现可以用并查集来做--但是当我们仔细阅读题面后,会发现其实并没有那么简单. 我们知道并查集可以很轻松地维护具有传递性的信息,也就 ...
- find_all的用法 Python(bs4,BeautifulSoup)
find_all()简单说明: find_all() find_all() 方法搜索当前tag的所有tag子节点,并判断是否符合过滤器的条件 用法一: rs=soup.find_all('a') 将返 ...
- jquery浅复制和深复制区别
jquery浅复制和深复制区别
- firebug和HTML查看源代码的区别
1.审查元素或者开发者工具或firebug看到的html是现在实时性的内容,经过js修改的: 2.而网页查看源代码看到的是最开始浏览器收到的HTTP响应,静态的html.