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. composer "Failed to decode zlib stream"

    dockerFile 中安装composer.... RUN curl -s -f -L -o /tmp/installer.php https://raw.githubusercontent.com ...

  2. [转]Centos 安装Sublime text 3

    本文简单介绍在CentOS上安装Sublime text 3, 转自:Centos 安装Sublime text 3 Step 1 :建立软件安装目录 # mkdir /opt # cd /opt S ...

  3. 【webService客户端】webservice客户端工具

    public static Object invokeWebService(String namespaces,String url, String method, Object[] params, ...

  4. 灵活、可高度自定义的——Progress进度圈、弹窗、加载进度、小菊花

    DDProgressHUD的介绍 提供了四种类型的展示: 显示无限旋转的加载图(比如小菊花,可以自定义),显示文字信息.网络刷新时经常用到. 显示加载进度的动画,也可以显示文字.网络下载时用的比较多, ...

  5. if 语句 写了return 报错

  6. MySQL V5.6.37升级到V5.6.38

    简单!万事先备份 cp /usr/my.cnf /home/xx/ cp -r /var/lib/mysql/dbname /home/xx/ mysqldump -u root -ppasswd - ...

  7. CasperJS断言

    特征 CasperJS具有一系列特征. 它具有一些列功能与断言,都是你期望一个好的测试API所具有的,包括: * assertTextExists (文本存在断言)* assertTitle (标题断 ...

  8. COM和.NET的互操作

    组件对象模型的基本知识         基于构件的软件开发日益流行,这里我吧自己在学校时整理的关于COM的一些东西献给大家,供初学者参考.一.组件(COM),是微软公司为了计算机工业的软件生产更加符合 ...

  9. sys和os模块

    一 sys 用于python解释器相关的操作 #!/usr/bin/env python # coding=utf-8 import time import sys def view_bar(num, ...

  10. 【windows】在控制面板卸载软件的时候,出现2502,2503的问题

    1. 打开“任务管理器”,找到“详细信息”的页签,将“explorer.exe”的进程结束任务 2.菜单栏的“文件”-->"建立新任务"--> 输入Explorer.e ...