Flyer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 386    Accepted Submission(s): 127

Problem Description
The new semester begins! Different kinds of student societies are all trying to advertise themselves, by giving flyers to the students for introducing the society. However, due to the fund shortage, the flyers of a society can only be distributed to a part of the students. There are too many, too many students in our university, labeled from 1 to 2^32. And there are totally N student societies, where the i-th society will deliver flyers to the students with label A_i, A_i+C_i,A_i+2*C_i,…A_i+k*C_i (A_i+k*C_i<=B_i, A_i+(k+1)*C_i>B_i). We call a student "unlucky" if he/she gets odd pieces of flyers. Unfortunately, not everyone is lucky. Yet, no worries; there is at most one student who is unlucky. Could you help us find out who the unfortunate dude (if any) is? So that we can comfort him by treating him to a big meal!
 
Input
There are multiple test cases. For each test case, the first line contains a number N (0 < N <= 20000) indicating the number of societies. Then for each of the following N lines, there are three non-negative integers A_i, B_i, C_i (smaller than 2^31, A_i <= B_i) as stated above. Your program should proceed to the end of the file.
 
Output
For each test case, if there is no unlucky student, print "DC Qiang is unhappy." (excluding the quotation mark), in a single line. Otherwise print two integers, i.e., the label of the unlucky student and the number of flyers he/she gets, in a single line.
 
Sample Input
2
1 10 1
2 10 1
4
5 20 7
6 14 3
5 9 1
7 21 12
 
Sample Output
1 1
8 1
 
Source
 
Recommend
liuyiding
 

因为最多一个奇数的,所以总数是奇数的。

二分区间就可以了。

比赛时候二分的 l,r都是int存的,导致算mid = (l+r)/2的时候溢出了,TAT

这样TLE了好久,我艹。。。。。

水题一发

 /* ***********************************************
Author :kuangbin
Created Time :2013/9/28 星期六 13:00:24
File Name :2013长春网络赛\1010.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const int MAXN = ;
long long A[MAXN];
long long B[MAXN];
long long C[MAXN];
int n;
inline long long calc(long long start,long long add,long long end)
{
return (end-start+ + add-)/add;
}
inline bool check(long long l,long long r)
{
long long sum = ;
for(int i = ;i < n;i++)
{
long long end = min(B[i],r);
if(end < A[i])continue;
if(l >end)continue;
long long s1;
s1 = calc(A[i],C[i],end);
if(l <= A[i])sum += s1;
else sum += s1 - calc(A[i],C[i],l-); }
if(sum % == )return false;
return true;
}
long long ttt(long long l,long long r)
{
long long sum = ;
for(int i = ;i < n;i++)
{
long long end = min(B[i],r);
if(end < A[i])continue;
if(l > end)continue;
long long s1,s2;
s1 = calc(A[i],C[i],end);
if(l <= A[i])sum += s1;
else sum += s1 - calc(A[i],C[i],l-); }
return sum;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n) == && n)
{
long long l = 100000000000LL, r = ;
for(int i = ;i < n;i++)
{
scanf("%I64d%I64d%I64d",&A[i],&B[i],&C[i]);
l = min(l,A[i]);
r = max(r,B[i]);
}
if(check(l,r) == false)
{
printf("DC Qiang is unhappy.\n");
continue;
}
while(l < r)
{
long long mid = (l+r)/;
if(check(l,mid))
{
r = mid;
}
else l = mid+;
}
printf("%d %d\n",(int)l,(int)ttt(l,l));
}
return ;
}

HDU 4768 Flyer (2013长春网络赛1010题,二分)的更多相关文章

  1. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU 4764 Stone (2013长春网络赛,水博弈)

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

  4. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  5. hdu 5441 (2015长春网络赛E题 带权并查集 )

    n个结点,m条边,权值是 从u到v所花的时间 ,每次询问会给一个时间,权值比 询问值小的边就可以走 从u到v 和从v到u算不同的两次 输出有多少种不同的走法(大概是这个意思吧)先把边的权值 从小到大排 ...

  6. hdu 4813(2013长春现场赛A题)

    把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...

  7. HDU 4763 Theme Section (2013长春网络赛1005,KMP)

    Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  9. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. swift相关文档

    swift官方文档 swift官方文档 https://itunes.apple.com/cn/book/swift-programming-language/id881256329?mt=11 sw ...

  2. oracle的中文排序问题

    mysql中文排序有convert(name using gbk)这样的函数,于是研究了一下oracle中文排序: 使用拼音排序 SQL> select * from chineseordert ...

  3. 大数据系列之数据仓库Hive命令使用及JDBC连接

    Hive系列博文,持续更新~~~ 大数据系列之数据仓库Hive原理 大数据系列之数据仓库Hive安装 大数据系列之数据仓库Hive中分区Partition如何使用 大数据系列之数据仓库Hive命令使用 ...

  4. Robotium_断言方法assert、is、search

    下面的这些方法都主要用来判断测试结果是否与预期结果相符,一般把is和search方法放在assert里面判断.assert最常用的还是assertThat方法,是Junit的判断,这里就不多说了.断言 ...

  5. ssh命令集锦

    [前提] ssh命令其实平时工作会比较少能够用到(因为直接用远程客户端来连接) 但是偶尔还是需要利用ssh临时的连接到某个服务器,所以当遇到的时候来总结一下 [集锦] 一.ssh以某个用户名连接到某个 ...

  6. 【转】使用import scope解决maven继承(单)问题

    http://blog.csdn.net/mn960mn/article/details/50894022 测试环境 maven 3.3.9 想必大家在做SpringBoot应用的时候,都会有如下代码 ...

  7. JS模块化编程(一):CommonJS,AMD/CMD

    前言 模块化是什么? 为什么采用模块化? 场景: 一个html,因不同的业务需求开发,会不断的引入js文件.另外,a.js和b.js中的变量或函数必须是全局的,才能暴露给使用方. <script ...

  8. mysql多表查询,group by并将结果导出来csv文件

    SQL手动操作得少,遇到一个CASE,就记录一个CASE吧. 今天遇到的是统计一个发布结果. 这个发布表中,有两个字段是外键,并且要求按其中一个外键,作group by操作, 最后,导出来excel能 ...

  9. js字符串驼峰和下划线互相转换

    // 下划线转换驼峰 function toHump(name) { return name.replace(/\_(\w)/g, function(all, letter){ return lett ...

  10. 【noip模拟赛2】牛跳

    描述 John的奶牛们计划要跳到月亮上去.它们请魔法师配制了P(1 <= P <=150,000)种药水,这些药水必需安原来的先后次序使用,但中间可以跳过一些药水不吃.每种药水有一个“强度 ...