HDU 4768: Flyer

题意:

有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2...  && A+k*C <= B)。题目保证最多有一个人收到的传单数是奇数。求如果有人收到传单是奇数,输出编号和他收到的传单数。

思路:

观察最后情况,可以发现,要么每个人都是偶数。要么有一个是奇数。观察其前缀和,发现奇数那个人之前的前缀和都是偶数,之后都是奇数。所以,二分之。

代码:

(上交大牛代码……)

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm> using namespace std; int n, a[100001][3];
long long sum; bool check(int now){
long long sum = 0;
for (int i = 1; i <= n; i++)
if (now >= a[i][0])
{
int Right = min(a[i][1], now);
if (a[i][2]) sum += (long long)(Right - a[i][0]) / a[i][2] + 1;
else sum++;
}
return(sum & 1);
} int read(){
char ch;
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar());
int cnt = 0;
for (; ch >= '0' && ch <= '9'; ch = getchar()) cnt = cnt * 10 + ch - '0';
return(cnt);
} int main(){
//freopen("j.in", "r", stdin);
//freopen("j.out", "w", stdout);
for (;;)
{
if (scanf("%d", &n) != 1) return 0;
sum = 0;
int Max = 0;
for (int i = 1; i <= n; i++)
{
a[i][0] = read(); a[i][1] = read(); a[i][2] = read();
if (a[i][2]) sum += (long long)(a[i][1] - a[i][0]) / a[i][2] + 1;
else sum++;
Max = max(Max, a[i][1]);
}
if (!(sum & 1))
{
printf("DC Qiang is unhappy.\n");
continue;
}
long long Left = 0, Right = Max, Mid = (Left + Right) >> 1;
while (Left + 1 < Right)
{
if (check(Mid)) Right = Mid;
else Left = Mid;
Mid = (Left + Right) >> 1;
}
printf("%d", Right);
int cnt = 0;
for (int i = 1; i <= n; i++)
if (Right >= a[i][0] && Right <= a[i][1] && !((Right - a[i][0]) % a[i][2])) ++cnt;
printf(" %d\n", cnt);
}
}

hdu 4678的更多相关文章

  1. hdu 4678 Mine

    HDU 4678 把点开空地时会打开的一大片区域看成一块,题目中说到,在一盘游戏 中,一个格子不可能被翻开两次,说明任意两块空地不会包含相同的格子. 那么就可以看成一个组合游戏. 当空地旁边没连任何数 ...

  2. HDU 4678 Mine SG博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=4678 自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG 这里子游戏之间没有影响 ...

  3. hdu 4678 Mine 博弈论

    这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...

  4. HDU 4678 Mine (2013多校8 1003题 博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  5. HDU 4678 Mine(博弈)

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  6. 【 2013 Multi-University Training Contest 8 】

    HDU 4678 Mine 对于每个空白区域,求SG值. 最后异或起来等于0,先手必败. #pragma comment(linker,"/STACK:102400000,102400000 ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. JDBC连接SQL Server

    下载jdbc驱动包 下载地址,我下载的是exe版本的,其实是格自解压包.下载完毕之后,双击运行,会解压在当前目录下. Microsoft SQL Server JDBC Driver 3.0\sqlj ...

  2. 【hdu4035】Maze

    Portal --> hdu4035 Solution 讲道理不是很懂为啥概d那么喜欢走迷宫qwq (推式子推的很爽的一题?) 首先大力dp列式子 用\(f[i]\)表示从\(i\)到离开的期望 ...

  3. win7右键新建文件夹不见了

    http://zhidao.baidu.com/question/175786636169796084.html 看下注册表文件:reg add "HKEY_CLASSES_ROOT\Dir ...

  4. opencv2 直方图之calchist函数使用(转)

    OpenCV提供了calcHist函数来计算图像直方图. 其中C++的函数原型如下:void calcHist(const Mat* arrays, int narrays, const int* c ...

  5. python常用序列list、tuples及矩阵库numpy的使用

    近期开始学习python机器学习的相关知识,为了使后续学习中避免编程遇到的基础问题,对python数组以及矩阵库numpy的使用进行总结,以此来加深和巩固自己以前所学的知识. Section One: ...

  6. 「Django」rest_framework学习系列-API访问跨域问题

    #以中间件方式解决API数据访问跨域问题1.API下新建文件夹下写PY文件a.引入内置类继承: from django.middleware.common import MiddlewareMixin ...

  7. python 删除文件/夹

    原文 : http://www.cnblogs.com/SophiaTang/archive/2012/01/16/2323467.html import os 删除文件: os.remove() 删 ...

  8. codeforces 876 C. Classroom Watch

    http://codeforces.com/contest/876/problem/C C. Classroom Watch time limit per test 1 second memory l ...

  9. poj 3164 Command Network(最小树形图模板)

    Command Network http://poj.org/problem?id=3164 Time Limit: 1000MS   Memory Limit: 131072K Total Subm ...

  10. 817C. Really Big Numbers 二分

    LINK 题意:给出两个数n, s,要求问1~n中\(x-bit(x)>=s\)的数有多少个.其中bit(x)指x的各位数之和 思路:首先观察能够发现,对于一个数如果满足了条件,由于x-bit( ...