版权声明:本文为博主原创文章。未经博主同意不得转载。 https://blog.csdn.net/u011328934/article/details/37612503

题目链接:uva 11237
- Halloween treats

题目大意:有c个小孩要到邻居家去要糖果。有n户邻居。每户邻居仅仅会提供固定数量的糖果,熊孩子们为了不发生冲突,决定将取来的糖果平均分配,问说取那几家邻居的糖果能够做到平均分配。注意n ≥ c。

解题思路:抽屉原理。求出序列的前缀和,有n个,将前缀和对c取模后。依据剩余系定理肯定是在0~c-1之间的,假设是0那么答案就不用说了,假设两端前缀和同余,则说明中间该段的和是c的倍数。

又由于n ≥ c,对于取0的时候肯定是能够有解的,那么n个数相应c-1个位置。肯定有同余的情况。

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int maxn = 100000;
int a[maxn+5], s[maxn+5], vis[maxn+5]; int main () {
int c, n;
while (scanf("%d%d", &c, &n) == 2 && c + n) {
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
memset(vis, -1, sizeof(vis)); vis[0] = s[0] = 0;
for (int i = 1; i <= n; i++) {
s[i] = (s[i-1] + a[i]) % c; if (vis[s[i]] == -1)
vis[s[i]] = i;
else {
for (int j = vis[s[i]] + 1; j <= i; j++)
printf("%d%c", j, j == i ? '\n' : ' ');
break;
}
}
}
return 0;
}

uva 11237 - Halloween treats(抽屉原理)的更多相关文章

  1. UVA 11237 - Halloween treats(鸽笼原理)

    11237 - Halloween treats option=com_onlinejudge&Itemid=8&page=show_problem&category=516& ...

  2. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. UVa 202 Repeating Decimals(抽屉原理)

    Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...

  5. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6631   Accepted: 2448 ...

  6. HDU 1808 Halloween treats(抽屉原理)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1808 Problem Description Every year there is the same ...

  7. Halloween treats HDU 1808 鸽巢(抽屉)原理

    Halloween treats Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)

    [POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...

  9. POJ 3370 Halloween treats 鸽巢原理 解题

    Halloween treats 和POJ2356差点儿相同. 事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列.并且有这种数列也必然能够找到. #include ...

随机推荐

  1. jdk动态代理使用及原理

    jdk动态代理的使用 1.创建实现InvocationHandler接口的类,实现invoke(Object proxy, Method method, Object[] args)接口,其中invo ...

  2. Educational Codeforces Round 40 I. Yet Another String Matching Problem

    http://codeforces.com/contest/954/problem/I 给你两个串s,p,求上一个串的长度为|p|的所有子串和p的差距是多少,两个串的差距就是每次把一个字符变成另一个字 ...

  3. UVA-11478 Halum (差分约束系统)

    题目大意:一张n个节点的有向带边权图,每次操作能任选一个节点v个一个整数d,使以v为终点的边权值都减少d,以v为起点的边权值都增加d,求若干次操作后的最小边权值的非负最大值. 题目分析:用sum[i] ...

  4. 利用PXE引导安装centos7

    # 利用PXE引导安装centos7 # ###简介### > PXE (Pre-boot Execution Environment,PXE client 在网卡的 ROM 中,当计算机引导时 ...

  5. IOS UI-控制器的生命周期

    一.控制器的生命周期 代码 @interface NJOneViewController () @property (nonatomic, strong) NSArray *foods; @end @ ...

  6. ActiveMQ教程(简介与安装)

    ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久 ...

  7. 快速切题 poj 1002 487-3279 按规则处理 模拟 难度:0

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 247781   Accepted: 44015 Descr ...

  8. bzoj1269

    题解: splay维护 只不过变成了字符串 代码: #include<bits/stdc++.h> using namespace std; +,BS= + ,BN= + ; ,head, ...

  9. LeetCode OJ:Letter Combinations of a Phone Number(数字字母组合)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  10. core文件介绍

    原文链接:http://team.eyou.com/?p=27 如有侵犯您的版权,请联系windeal12@qq.com linux下,产生core文件,和不产生core文件的条件: 当我们的程序崩溃 ...