Halloween treats HDU 1808 鸽巢(抽屉)原理
Halloween treats
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1097 Accepted Submission(s): 435
Special Judge
Your job is to help the children and present a solution.
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 a1 , ... , an (1 ≤ ai ≤ 100000 ), where ai represents the number of sweets the children get if they visit neighbour i.
The last test case is followed by two zeros.
1 2 3 7 5
3 6
7 11 2 5 13 17
0 0
2 3 4
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
ll vis[maxn], a[maxn];
int main() {
std::ios::sync_with_stdio(false);
ll n, m;
while( cin >> n >> m ) {
if( !n && !m ) {
break;
}
ll sum = 0, t;
memset( vis, 0, sizeof(vis) );
for( ll i = 1; i <= m; i ++ ) {
cin >> a[i];
}
for( ll i = 1; i <= m; i ++ ) {
sum += a[i];
t = sum%n;
if( t == 0 ) {
for( ll j = 1; j < i; j ++ ) {
cout << j << " ";
}
cout << i << endl;
break;
} else if( vis[t] ) { //如果余数在前面出现过,现在又出现了,则中间一定加了n的倍数
for( ll j = vis[t]+1; j < i; j ++ ) {
cout << j << " ";
}
cout << i << endl;
break;
}
vis[t] = i;
}
}
return 0;
}
Halloween treats HDU 1808 鸽巢(抽屉)原理的更多相关文章
- [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)
[POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...
- HDU 1205 鸽巢原理
#include <bits/stdc++.h> using namespace std; long long abs_(long long a,long long b) { if(a&g ...
- HDU 5776 sum(抽屉原理)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=5776 Problem Description Given a sequence, you're ask ...
- hdu 1205 吃糖果 (抽屉原理<鸽笼原理>)
吃糖果Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submissi ...
- HDU 1808 Halloween treats(抽屉原理)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1808 Problem Description Every year there is the same ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ3370&HDU1808 Halloween treats【鸽巢原理】
题目链接: id=3370">http://poj.org/problem?id=3370 http://acm.hdu.edu.cn/showproblem.php?pid=1808 ...
- POJ 3370 Halloween treats 鸽巢原理 解题
Halloween treats 和POJ2356差点儿相同. 事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列.并且有这种数列也必然能够找到. #include ...
- POJ 3370 Halloween treats( 鸽巢原理简单题 )
链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...
随机推荐
- Docker 容器高级操作[Docker 系列-3]
关注公众号,大家可以在公众号后台回复“博客园”,免费获得作者 Java 知识体系/面试必看资料. 上篇文章向读者介绍了一个 Nginx 的例子,对于 Nginx 这样一个容器而言,当它启动成功后,我们 ...
- codeforces 355A Vasya and Digital Root
题意就是找出一个长度为k的整数,使得它的root为d,k的可能取值为1-1000. 第一眼看到这个题,无从下手,想到那么长的数,暴力肯定超时.其实不然,题目要求只要输出任何一个满足条件的即可,因为任何 ...
- JavaSE之——并没有多维数组
近日在读<疯狂Java讲义>精粹第二版,部分语述摘自其中,自己边敲边理解 前言 我们知道,Java语言支持的类型有两种: 1.基本类型(即八大基本数据类 ...
- 疯子的算法总结(三) STL Ⅱ迭代器(iterator) + 容器
一.迭代器(Iterator) 背景:指针可以用来遍历存储空间连续的数据结构,但是对于存储空间费连续的,就需要寻找一个行为类似指针的类,来对非数组的数据结构进行遍历. 定义:迭代器是一种检查容器内元素 ...
- Template(模板)模式
第三章:模板模式 Template模式比较简单,是基于继承关系的一种设计模式,由父类定义处理流程框架,由子类中实现具体处理. Code: package example.template; /*** ...
- sublime text 3 15个常用插件介绍
1.ColorPicker 功能:调色板(需要输入颜色时,可直接选取颜色) 使用:快捷键Windows: ctrl+shift+c 2.Emmet 功能:编码快捷键,前端必备 使用:在输入代码段后,按 ...
- soap天气查询
public class MainActivity extends AppCompatActivity { private TextView tvContent; @Override protecte ...
- windows查看端口被占用
1.打开控制台终端 2.在命令行下输入netstat -ano|findstr "8080"(8080是被占用的端口) 3.记住最后一列的数字PID如4684 4.输入taskli ...
- 基于jmeter+perfmon的稳定性测试记录
1. 引子 最近承接了项目中一些性能测试的任务,因此决定记录一下,将测试的过程和一些心得收录下来. 说起来性能测试算是软件测试行业内,有些特殊的部分.这部分的测试活动,与传统的测试任务差别是比较大的, ...
- C#之BackgroundWorker从简单入门到深入精通的用法总结
需求分析 经常用到的耗时操作,例如: 1.文件下载和上载(包括点对点应用程序传输文件,从网络下载文件.图像等)2.数据库事务(从数据库读到大量的数据到WinForm界面中的DataGridview里呈 ...