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 ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...
随机推荐
- 后台post注入爆密码
后台登陆框post注入按照注入的方式属于post,和前台搜索型post注入.文本框注入类似,由于目前主流的注 入工具除了穿山甲等较新工具以外几乎都是get注入,尤其是对于这种后台账户型post注入式无 ...
- 关于http 500错误的小结分享
一般情况下,http 500内部服务器(HTTP-Internal Server Error)错误说明IIS服务器无法解析ASP代码,访问一个静态页面试试是否也出现这个问题. 如果访问静态页面没问题, ...
- 数据结构之堆栈C++版
/* 堆栈本身就是一种线性数据结构,说白了他与容器线性表是一种数据类型,不要认为他多高大上. 实时上他还没有线性表复杂,下面简单的实现一下堆栈. 事实上整个核心操作都是在操作指向堆栈的顶部元素的指针 ...
- Jersey用户指南学习笔记1
Jersey用户指南是Jersey的官方文档, 英文原版在这:https://jersey.github.io/documentation/latest/index.html 中文翻译版在这:http ...
- SAP无法激活表问题
因为修改了表结构导致无法激活,刚开始以为是数据库没有调整,然后试着运行SE14,发现还是报错 这个时候就要看看数据库服务器时候正常,输入事务码ST04,查看概览,发现磁盘已满 登录HANA Studi ...
- Jvm内存泄漏
内存泄漏和内存溢出的关系 内存泄露:指程序中动态分配内存给一些临时对象,但是对象不会被GC所回收,它始终占用内存.即被分配的对象可达但已无用. 内存溢出:指程序运行过程中无法申请到足够的内存而导致的一 ...
- Kendo-Grid for Vue API and Template
写此博客的原因:在做项目时前端用的vue,后端用的jfinal.在前端veu中调用了kendo grid插件,但是在官方文档中对kendo grid for vue 的api和template都不太详 ...
- Windows Server 2008配置系统安全策略
下面学习Windows Server 2008配置系统安全策略 在工作组中的计算机本地安全策略有 用户策略,密码策略,密码过期默认42天 服务账户设置成永不过期,帐户锁定策略,本地策略,审核策略,计算 ...
- Linux - 通过expect工具实现脚本的自动交互
目录 1 安装expect工具 2 expect的常用命令 3 作用原理简介 3.1 示例脚本 3.2 脚本功能解读 4 其他脚本使用示例 4.1 直接通过expect执行多条命令 4.2 通过she ...
- MongoDB实现评论榜
Mongodb很适合做这件事,api的调用仅仅是使用到了入门级别的CRUD,理清楚了思路,编码也会顺风顺水,所以你会发现我在这篇博客中说的比编码还多 评论榜预期的功能 就像是StackOverFlow ...