Halloween treats

和POJ2356差点儿相同。

事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列。并且有这种数列也必然能够找到。

#include <cstdio>
#include <cstdlib>
#include <xutility> int main()
{
int c, n;
while (scanf("%d %d", &c, &n) && c)
{
int *neighbours = (int *) malloc(sizeof(int) * n);
int *sumMod = (int *) malloc(sizeof(int) * (n+1));
int *iiMap = (int *) malloc(sizeof(int) * c);
std::fill(iiMap, iiMap+c, -1); sumMod[0] = 0;
int L = -1, R = -1; for (int i = 0; i < n; i++) scanf("%d", &neighbours[i]); for (int i = 0; i < n; i++)
{
sumMod[i+1] = (sumMod[i] + neighbours[i]) % c; if (sumMod[i+1] == 0)
{
L = 1, R = ++i;//下标从1起
break;
} if (iiMap[sumMod[i+1]] != -1)
{
L = iiMap[sumMod[i+1]] + 2, R = ++i; //下标从1起
break;
} iiMap[sumMod[i+1]] = i;
} if (R != -1)
{
for (int i = L; i < R; i++)
{
printf("%d ", i);
}
printf("%d\n", R);
}
else puts("no sweets"); free(neighbours), free(iiMap), free(sumMod);
}
return 0;
}

POJ 3370 Halloween treats 鸽巢原理 解题的更多相关文章

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

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

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

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

  3. POJ 3370 Halloween treats( 鸽巢原理简单题 )

    链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...

  4. [POJ 3370] Halloween treats

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7143   Accepted: 2641 ...

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

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

  6. poj 3370 Halloween treats(鸽巢原理)

    Description Every year there is the same problem at Halloween: Each neighbour is only willing to giv ...

  7. 鸽巢原理应用-分糖果 POJ 3370 Halloween treats

    基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: Description Every year there is the same pro ...

  8. POJ3370&amp;HDU1808 Halloween treats【鸽巢原理】

    题目链接: id=3370">http://poj.org/problem?id=3370 http://acm.hdu.edu.cn/showproblem.php?pid=1808 ...

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

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

随机推荐

  1. $P1596 [USACO10OCT]湖计数Lake Counting$

    \(problem\) 其实这题吧\(DFS\)好写一点(大雾 所以就不讲\(DFS\)了 em \(BFS\)的话 主要是 判重. 方向. 队列.(没了吧 至于位置 用两个队列?还是\(pair\) ...

  2. React Native导航器Navigator

    React Native导航器Navigator 使用导航器可以让你在应用的不同场景(页面)间进行切换.导航器通过路由对象来分辨不同的场景.利用renderScene方法,导航栏可以根据指定的路由来渲 ...

  3. 实现PC延迟执行函数

    头文件内容: #pragma once typedef function<void ()> DelayClickHandler; typedef void (*pDelayFun)(); ...

  4. web流行工具

    中小型公司: Node.js:现代工业化前端的基础: RequireJS:AMD规范, 即将过时的 JavaScript 模块化方案: Bower:前端模块源: npm:前端工具源,另一个潜在的前端模 ...

  5. svg文件使用highmap显示

    svg文件使用highmap显示 highmap,ammap都是比较好的第三方插件用来显示svg图片:     ammap导航可能更美观点(这个highmap后面可能也会赶上),     highma ...

  6. PHP 之微信小程序支付封装

    <?php /** * Created by PhpStorm. * User: yangs * Date: 2019/4/26 * Time: 14:28 */ class WeixinPay ...

  7. 关于static关键字的思考

    静态方法是否能调用非静态成员变量?    static关键字具有如下特点:        一.static关键字修饰的属性/方法可以通过类名直接调用,而不必先new一个对象.        二.sta ...

  8. 新版本的molar mass(uva-1586)明明debug过了,各种测试还是WA真是气死我了

    #include <bits/stdc++.h> using namespace std; double trans(string a) { stringstream ss; ss< ...

  9. [luogu2148 SDOI2009] E&D (博弈论)

    传送门 Solution 我们知道当SG不为0则先手必胜,然后就可以打表了 ̄▽ ̄ Code //By Menteur_Hxy #include <cmath> #include <c ...

  10. pyhon中的内存优化机制

    一.变量的内存地址 python中变量的内存地址可以用id()来查看 >>> a = " >>> id(a) 2502558915696 二.pyhon中 ...