题目链接:

传送门

思路:

这个是鸽笼原理的题目。。。看了一下这个原理,对此的理解是分为三点。。
c代表人的数目,n代表家庭的数目。。
【1】首先要求前缀和,然后对此取余,首先如果出现余数为0的情况,那么说明前n项就已经满足了条件,那么这就是其中的一组可行解。。。
【2】但是如果没有出现0呢??那么就看同余了。。如果在两个点处出现同余,说明什么??说明从上一个出现同余的后一个数到这个数的和为c的倍数,那么就得到了一组可行解。。
【3】题目说没有情况则输出“no sweetws”,但是说明情况下出现呢???只有当不出现【1】【2】的情况,当说明时候不出现呢???那么就是n<c的时候可能会出现不可能的情况,因为可能不会出现同余的情况,但是如果n>=c的话肯定会出现两个点处出现同余。。
那么这个问题就解决了。。。

题目:
Halloween treats
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6638   Accepted: 2451   Special Judge

Description

Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a child will get nothing if it is too late. To avoid conflicts, the children have decided they will put all sweets together and then divide them evenly among themselves. From last year's experience of Halloween they know how many sweets they get from each neighbour. Since they care more about justice than about the number of sweets they get, they want to select a subset of the neighbours to visit, so that in sharing every child receives the same number of sweets. They will not be satisfied if they have any sweets left which cannot be divided.

Your job is to help the children and present a solution.

Input

The 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 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.

Output

For 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 ai 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

Source

Ulm Local 2007
代码:
#include<cstdio>
#include<cstring>
const int maxn=100000+10;int a[maxn],mod[maxn];
int c,n;int main()
{__int64 sum;while(~scanf("%d%d",&c,&n)){if(c==0&&n==0)  return 0;sum=0;for(int i=1;i<=n;i++)scanf("%d",&a[i]);for(int i=0;i<c;i++)mod[i]=-1;for(int i=1;i<=n;i++){sum=(sum+a[i])%c;if(sum==0){for(int j=1;j<i;j++)printf("%d ",j);printf("%d\n",i);break;}if(mod[sum]!=-1){for(int j=mod[sum]+1;j<i;j++)printf("%d ",j);printf("%d\n",i);break;}mod[sum]=i;}}return 0;
}

poj3370Halloween treats(鸽笼原理)相关推荐

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

    11237 - Halloween treats 题目链接 题意:有c个小伙伴,n个房子(c <= n).每一个房子会给ai个糖果,要求选一些房子,使得得到的糖果能平均分给小伙伴,输出方案 思路 ...

  2. HDU 5762 Teacher Bo (鸽笼原理) 2016杭电多校联合第三场

    题目:传送门. 题意:平面上有n个点,问是否存在四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D)使得AB的横纵坐标差的绝对值的和等于CD的横纵坐标差的绝对值的和,n<1 ...

  3. Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)

    To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a ...

  4. CF1379F1 Chess Strikes Back (easy version)(鸽笼原理、线段树)

    解析 很神奇的一道题 关键在于把22的正方形看成一个单位的转化 由于每个22最多有一个国王 因此每个2*2都一定有一个国王 这是本题的关键 个人感觉这个思想很像鸽笼原理 至于后面的线段树就水到渠成了 ...

  5. Loj#3077-「2019 集训队互测 Day 4」绝目编诗【结论,虚树,鸽笼原理】

    正题 题目链接:https://loj.ac/p/3077 题目大意 给出nnn个点mmm条边的一张简单无向图,求是否存在两个长度相等的简单环. 1≤n≤104,1≤m≤1061\leq n\leq ...

  6. YbtOJ-变量观测【鸽笼原理】

    正题 题目大意 有nnn个数字开始都是000,要求有qqq次操作. 新建一个观测员,观测其中的kkk个数,当这kkk个数从此刻开始变化量不小于ttt时观测结束. 将第iii个数加vvv,并输出此时观测 ...

  7. 从鸽笼原理到拉姆塞数

    1958年6-7月号美国的<数学月刊>上刊载着这样一个有趣的问题:"任何6个人的聚会,其中总会有3个人相互认识,或3个人相互不认识"(这是确定事件,不是以一定概率发生) ...

  8. 【jzoj 5101】凡喵识图 / Image Recognition(鸽笼原理)(模拟)

    凡喵识图 / Image Recognition 题目链接:jzoj 5101 题目大意 给你一些 2^64 大小的数,然后每插入一个数之前,询问原本有多少个数的二进制跟它的二进制恰好有三位不同. 思 ...

  9. 努力前端【LeetCode-10】448. 找到所有数组中消失的数字 442. 数组中重复的数据(中等) 41. 缺失的第一个正数(困难) [鸽笼原理,数组,Map,类似No.645]

    文章目录 题目描述-448 一.哈希Map 二.空间复杂度的优化--鸽笼原理 三.总结 题目描述-442 一.还是hashMap 二.继续鸽笼原理 题目描述-41 一.基础方案 二.数组模拟Map 题 ...

最新文章

  1. 田渊栋的2021年终总结:多读历史!历史就是一个大规模强化学习训练集
  2. html 浮动脱离文档流,CSS标准文档流与脱离文档流
  3. Navisworks API 简单二次开发 (自定义工具条)
  4. 云炬60s看世界20211128
  5. 【face-landmarks】人脸关键点检测汇总
  6. dubbo protocol port 消费者端_Dubbo源码:搞定URL,就走完了进度条的一半
  7. java direct memory_第一讲  JVM内存四大类型:Heap,Stack,Contant,DirectMemory等
  8. 为何数据治理如此重要
  9. 对lua 实现面向对象的理解
  10. Big Mart Sales prediction 商场销售预测分析项目
  11. ansible(一)自动化运维工具
  12. 中科探海的海底掩埋物三维实时成像声呐
  13. 领英辅助工具领英精灵自动加好友功能讲解
  14. matlab多重数值积分,Matlab数值积分和微分(一重、多重都有),简单实用。
  15. html打印时显示不全,打印表格时内容显示不完整怎么办?四种方法解决WPS不完整问题...
  16. 六、策略模式—旅行的交通工具 #和设计模式一起旅行#
  17. 江西 南昌 富士康 java,好消息!富士康智能科技小镇落户小蓝经开区!总投资达110亿元...
  18. 如何在工作之余找精力做副项目?
  19. linux系统文件系统格式转换--不丢文件
  20. 视频教程-JAVA WEB开发实战-Java

热门文章

  1. recast 1 rasterizeTri dividePoly
  2. 实时数据架构实时数据仓库,你到底了解多少?
  3. OpenCV-迷宫解密
  4. 网站建设之域名注册和域名备案
  5. CollectionView多选
  6. 如何将一个向量投影到一个平面上_线性代数19——投影矩阵和最小二乘
  7. 品牌活动如何策划,更利于传播?(吸引媒体报道)
  8. java计算机毕业设计小区停车场信息系统源码+系统+数据库+lw文档+mybatis+运行部署
  9. IDEA2021.2 JRebel CPU占用高
  10. 线性回归模型(OLS)1