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 ...
随机推荐
- Netty处理器重要概念
1.Netty的处理器可以分为两类:入站处理器和出战处理器 2.入站处理器顶层是ChannelInboundHandler,出战处理器顶层是ChannelOutboundHandler 3.数据处理时 ...
- Nginx Linux和Windows安装教程
前言 本篇文章主要介绍的是Nginx Linux环境和Windows的安装教程. Nginx 介绍 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Syso ...
- WeTest明星工具-移动端性能测试PerfDog初探
在十一月初,腾讯就官宣了一则消息,腾讯WeTest明星工具-PerfDog面向全球发布.官宣介绍如下:https://wetest.qq.com/lab/view/475.html.我在看到该新闻时, ...
- opencv 3 core组件进阶(2 ROI区域图像叠加&图像混合;分离颜色通道、多通道图像混合;图像对比度,亮度值调整)
ROI区域图像叠加&图像混合 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp&g ...
- Python 函数知识点整理
- 【MongoDB】用Docker安装一个MongoDB最新版玩玩
1 安装 本文假设大家已经安装好了docker并能正常使用,所以不讲解如何安装docker了.用docker安装MongoDB最新版本如下: # 从repository查找mongo的相关镜像,结果很 ...
- Ubuntu改坏sudoers后无法使用sudo的解决办法
练习安装odoo的时候,创建了一个odoo用户,想把它赋予sudo权限,然而,编辑的时候不留意,改坏了,导致sudo无法使用,无法编辑sudoers文件修改回来. 总提示如下信息: >>& ...
- 小白学 Python 爬虫(4):前置准备(三)Docker基础入门
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- Jrebel 激活的方法
jrebel 激活的方法: 试了很多都不好用,下面这个方法比较简单快捷.(不知道可以坚持多久) myjrebel 7月分官方正式停用,致使广大朋友无法使用jrebel/XRebel,可按如下地址进行 ...
- FPGA基础(verilog语言)——语法篇(续1)
上一篇文章提到了FPGA中一个模块基本结构,这篇文章开始介绍语法. 首先,我们学习一门语言都要从这门语言的单词学起,所以verilog中的关键词都有哪些呢?看下面: A:always.assign B ...