HDU4768:Flyer [ 二分的奇妙应用 好题 ]
Flyer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1718 Accepted Submission(s): 622
1 10 1
2 10 1
4
5 20 7
6 14 3
5 9 1
7 21 12
8 1
12940329 | 2015-02-12 17:35:01 | Accepted | 4768 | 78MS | 1756K | 1933 B | G++ | czy |
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 20005
#define M 205
#define mod 10000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 100000000
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n;
ll a[N],b[N],c[N];
ll num[N];
ll ans;
ll ma;
ll cc; void ini()
{
int i;
ma=;
for(i=;i<=n;i++){
scanf("%I64d%I64d%I64d",&a[i],&b[i],&c[i]);
ma=max(ma,b[i]);
num[i]=(b[i]-a[i])/c[i]+;
}
} ll ok(ll l,ll r)
{
int i;
ll re;
re=;
ll t1,t2;
l--;
for(i=;i<=n;i++){
if(l>b[i] || r<a[i]) continue;
if(l<a[i]){
t1=;
}
else{
t1=(l-a[i])/c[i]+;
}
if(r>b[i]){
t2=num[i];
}
else{
t2=(r-a[i])/c[i]+;
}
re+=t2-t1;
}
if(re%==) return re;
else return ;
} void solve()
{
ll l,r,mid;
l=;r=ma;
while(l<r)
{
mid=(l+r)/;
cc=ok(l,mid);
if(cc!=)
{
r=mid;
}
else{
l=mid+;
}
}
ans=l;
cc=ok(l,l);
} void out()
{
if(cc==){
printf("DC Qiang is unhappy.\n");
}
else
printf("%I64d %I64d\n",ans,cc);
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
//scanf("%d%d",&n,&m);
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
ini();
solve();
out();
}
return ;
}
HDU4768:Flyer [ 二分的奇妙应用 好题 ]的更多相关文章
- Flyer(二分 HDU4768)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- HDU 6278 - Just h-index - [莫队算法+树状数组+二分][2018JSCPC江苏省赛C题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6278 Time Limit: 6000/3000 MS (Java/Others) Memory Li ...
- POJ 3104 Drying [二分 有坑点 好题]
传送门 表示又是神题一道 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9327 Accepted: 23 ...
- 【LeetCode】二分 binary_search(共58题)
[4]Median of Two Sorted Arrays [29]Divide Two Integers [33]Search in Rotated Sorted Array [34]Find F ...
- POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题
在一个n*m的草地上,.代表草地,*代表水,现在要用宽度为1,长度不限的木板盖住水, 木板可以重叠,但是所有的草地都不能被木板覆盖. 问至少需要的木板数. 这类题的建图方法: 把矩阵作为一个二分图,以 ...
- hdu 4768 Flyer 二分
思路:由于最多只有一个是奇数,所以二分枚举这个点,每次判断这个点的左边区间段所有点的和作为 二分的依据. 代码如下: #include<iostream> #include<cstd ...
- HDU 3861 The King’s Problem(tarjan缩点+最小路径覆盖:sig-最大二分匹配数,经典题)
The King’s Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HihoCoder 1053 : 居民迁移 二分+贪心+双指针(好题)
居民迁移 时间限制:3000ms 单点时限:1000ms 内存限制:256MB 描述 公元2411年,人类开始在地球以外的行星建立居住点.在第1326号殖民星上,N个居住点分布在一条直线上.为了方便描 ...
- poj2226-Muddy Fields二分匹配 最小顶点覆盖 好题
题目 给到一个矩阵,有些格子上是草,有些是水.需要用宽度为1,长度任意的若干块木板覆盖所有的水,并不能覆盖草,木板可以交叉,但只能横竖放置,问最少要多少块板. 分析 经典的矩阵二分图构图和最小点覆盖. ...
随机推荐
- ftpaccess - ftpd的配置档
描述 DESCRIPTION 这个ftpaccess档案是用来配置下述功能的运作 存取功能(AccessCapabilities) autogroup<群组名称><类别>[&l ...
- js 两个数组进行去重处理,返回去重后的数组
1.去重的方法为: array_diff(a, b) { for (var i = 0; i < b.length; i++) { for (var j = 0; j < a.length ...
- POI写入word doc 03 模板的实例
在使用POI写word doc文件的时候我们必须要先有一个doc文件才行,因为我们在写doc文件的时候是通过HWPFDocument来写的,而HWPFDocument是要依附于一个doc文件的.所以通 ...
- shell脚本,通过传参求斐波那契数列如(0,1,1,2,3,5,8,13..........)
[root@localhost wyb]# cat fibo.sh #!/bin/bash #斐波那契数列 ,,,,,,, > file >> file count=$ for i ...
- bzoj5286 [Hnoi2018]转盘
题目描述: bz luogu 题解: 看了半个晚上终于明白了. 首先最优决策一定有:在起始点停留一段时间然后一直前进. 解释网上有很多,在这里不赘述了. (由于是环,先把$T$数组倍长.) 首先基于决 ...
- PHP 线上项目 无法操作
部署到线上的项目,http 环境没有问题,首页展示没有问题,但是跳转页面展示到了本地, 解决办法 : 更改文件夹所属用户 chown -R apache:apache html
- 重置windows用户漫游配置文件
1.备份用户数据 2.删除或修改漫游配置文件 3.用户PC管理员登陆,删除本地用户缓存文件 注册表打开: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows N ...
- python数据类型、字符编码、文件处理
介绍: 1.什么是数据? 例:x=10,10是我们要存储的数据 2.为何数据要分不同的类型? 数据是用来表示状态的,不同的状态用不同的类型的数据去表示 1.数据类型 1.数字(整形,长整形,浮点型,复 ...
- laravel中文字模型的增删改查
模型是用ORM 来做, 使用类来表示一个表,每个表都对应一个模型,以供上层使用 创建模型在项目中的位置定位: /app/下面 好了,我们来创建一个模型: php artisan make:model ...
- i.mx53开发的一些问题
i.mx53开发的一些问题 转载于此:http://blog.csdn.net/shell_albert/article/details/8242288 原来i.mx53上4GB的Nand Fla ...