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 ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...
随机推荐
- codeforces 371A K-Periodic Array
很简单,就是找第i位.i+k位.i+2*k位...........i+m*k位有多少个数字,计算出每个数出现的次数,找到出现最多的数,那么K-Periodic的第K位数肯定是这个了.这样的话需要替换的 ...
- for循环打印空心菱形的新方法
相信大家在学习流程控制的循环结构时,一定都用for循环绘制过菱形和空心菱形吧,我记得我当时写的很麻烦,把一个菱形分为上下两部分,上面2重for循环,下面2重for循环,相信有很多的小伙伴都是这样做的吧 ...
- 8天入门docker系列 —— 第八天 让程序跑在swarm集群上
真正的落地部署都是希望程序跑在集群下,而不是单机版下测测玩玩,所以这篇就来聊一下怎么使用docker swarm进行部署,因为是swarm是docker自带的, 所以部署起来还是非常简单的. 一:前置 ...
- Zabbix编译安装(全)
一.前言 (一).概述 Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案,Zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系 ...
- CEPH 对象存储的系统池介绍
RGW抽象来看就是基于rados集群之上的一个rados-client实例. Object和pool简述 Rados集群网上介绍的文章很多,这里就不一一叙述,主要要说明的是object和pool.在r ...
- MQ如何解决消息的顺序性
一.消息的顺序性 1.延迟队列:设置一个全局变量index,根据实际情况一次按照index++的逻辑一次给消息队列设置延迟时间段,可以是0.5s,甚至1s; 弊端:如果A,B,C..消息队列消费时间不 ...
- Vue小事例
login <!DOCTYPE html><html lang="ZH-cn"> <head> <meta charset="U ...
- .netcore持续集成测试篇之搭建内存服务器进行集成测试一
系列目录 在web项目里,我们把每一层的代码的单元测试都通过并不代表程序能正常运行,因为这个过程缺失了http管道,很多时候我们还还需要把项目布在iis环境中或者在vs里启动iis express服务 ...
- Android——倒计时跳转+sharedpreferences
public class MainActivity extends Activity { // 3秒钟后,从图1跳转到图2(10) private Handler handler=new Handle ...
- HashMap源码分析之面试必备
今天我们就面试会问到关于HashMap的问题进行一个汇总,以及对这些问题进行解答. 1.HashMap的数据结构是什么? 2.为啥是线程不安全的? 3.Hash算法是怎样实现的? 4.HashMa ...