HDU 4768 Flyer (2013长春网络赛1010题,二分)

时间:2023-02-25 13:07:36

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 &lpar;2013长春网络赛,水博弈&rpar;

    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. Linux shell basic3 dd wc comm chmod ls

    Generating files of any size /dev/zerois a character special device, which infinitely returns the ze ...

  2. js中的if判断十分优美的简洁写法

    本尊混迹猿人类也有5年有余,从最开始的C#到java再到php到至今的python,不能说精通,也算得上是熟悉,对各个语言的语法也算是了解. 虽然目前在开发web程序,了解一些java知识,但是今天在 ...

  3. select框的text与value值的获取&lpar;实用版&rpar;

    function def(){    var key = document.getElementById ('selectarea'); //select list var value = docum ...

  4. 【甘道夫】HBase基本数据操作的详细说明【完整版,精绝】

    介绍 之前具体写了一篇HBase过滤器的文章.今天把基础的表和数据相关操作补上. 本文档參考最新(截止2014年7月16日)的官方Ref Guide.Developer API编写. 全部代码均基于& ...

  5. javascript的stringFormat函数实现

    写一个简单的stringFormat来给自己用 function stringFormat(format, args) { var formatData; if (arguments.length = ...

  6. python的学习笔记01&lowbar;1 python2和python3的区别和环境

    1.python2 与 python3 区别: 关于这两个版本的区别,从宏观上来讲: python2:源码不标准,混乱(很多技术大佬写的都有自己语言的特点,看起来很不pythoner)由于python ...

  7. mysql与mycat搭建实现集群与读写分离

    数据库性能优化普遍采用集群方式,oracle集群软硬件投入昂贵,今天花了一天时间搭建基于mysql的集群环境. 主要思路 简单说,实现mysql主备复制-->利用mycat实现负载均衡. 比较了 ...

  8. MongoDB分片集群原理、搭建及测试详解

    随着技术的发展,目前数据库系统对于海量数据的存储和高效访问海量数据要求越来越高,MongoDB分片机制就是为了解决海量数据的存储和高效海量数据访问而生. MongoDB分片集群由mongos路由进程( ...

  9. EL&lpar;Expression Language&rpar;和JSTL标签&lpar;JSP Standard Tag Library&rpar;

    一.EL表达式: Expression Language提供了在 JSP 脚本编制元素范围外(例如:脚本标签)使用运行时表达式的功能.脚本编制元素是指页面中能够用于在JSP 文件中嵌入 Java代码的 ...

  10. BZOJ&period;2724&period;&lbrack;Violet 6&rsqb;蒲公英&lpar;静态分块&rpar;

    题目链接 区间众数 强制在线 考虑什么样的数会成为众数 如果一个区间S1的众数为x,那么S1与新区间S2的并的众数只会是x或S2中的数 所以我们可以分块先预处理f[i][j]表示第i到第j块的众数 对 ...