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. 《Linux内核设计与实现》读书笔记——第一二章

    <Linux内核设计与实现>读书笔记——第一二章 第一章 Linux内核简介 1.1 Unix的历史 简洁:仅提供系统调用并有一个非常明确的设计目的. 抽象:Unix中绝大部分东西都被当做 ...

  2. 复习JavaScript随手记

    数据类型 基本类型 string number boolean undefined number类型,包含整数浮点数 NaN和自己都不相等,涉及NaN的计算结果都是NaN isNaN()函数用于判断一 ...

  3. 【计算机视觉】SIFT中LoG和DoG比较

    <SIFT原理与源码分析>系列文章索引:http://www.cnblogs.com/tianyalu/p/5467813.html 在实际计算时,三种方法计算的金字塔组数noctaves ...

  4. Codeforces 895.E Eyes Closed

    E. Eyes Closed time limit per test 2.5 seconds memory limit per test 256 megabytes input standard in ...

  5. 中南多校对抗赛 第三场 B

    B:Arithmetic Progressions 题意: 给你一个长度为n的序列,问你这个序列中长度最长的等差数列长度为多少 题解: 方法一:将数组从小到大排序,n方扫,枚举出公差d,然后二分找有多 ...

  6. python学习(十)元类

    python 可以通过`type`函数创建类,也可通过type判断数据类型 import socket from io import StringIO import sys class TypeCla ...

  7. K8S dashboard 创建只读账户

    1.创建名字为“Dashboard-viewonly“的Cluster Role,各种资源只给予了list,get,watch的权限.dashboard-viewonly.yaml --- apiVe ...

  8. Asp.Net MVC 自定义登录过滤器

    1.新建类BaseController用于统一所有控制器继承扩展,方便扩展登录等过滤器.示例如下: using CloudWave.JustBeHere.JBH_H5.Controllers.Attr ...

  9. poj 1067 取石子游戏 (威佐夫博弈)

    取石子游戏 http://poj.org/problem?id=1067 Time Limit: 1000MS   Memory Limit: 10000K       Description 有两堆 ...

  10. 【Project Euler】530 GCD of Divisors 莫比乌斯反演

    [题目]GCD of Divisors [题意]给定f(n)=Σd|n gcd(d,n/d)的前缀和F(n),n=10^15. [算法]莫比乌斯反演 [题解]参考:任之洲数论函数.pdf 这个范围显然 ...