CSU1204-Rectangles-二分
来源:互联网 发布:招聘网站源代码 java 编辑:程序博客网 时间:2024/06/03 15:24
X: Rectangles
Description
如果限定矩形的边长必须为整数,且周长为定值L,那么面积在[A, B]范围内不同的矩形一共有多少个呢?
在这个问题中,当且仅当两个矩形面积不同时,视作是两个不同的矩形。
Input
输入数据的第一行包含一个整数T (1 <= T <= 10000),表示接下来一共有T组测试数据。
对于每组测试数据,包含三个整数L (1 <= L <= 2,000,000,000)、A、B (1 <= A <= B <= 250,000,000,000,000,000),含义同上。
Output
对于每组测试数据,用一行输出一个整数,代表上述问题的答案。
Sample Input
311 1 612 5 1012 8 10
Sample Output
032
这么大的数据范围,当然是选择二分啦
就是二分找到边长的上下限,做差+1就是结果啦,因为边长只能是整数,具体的看代码体会吧
#include <iostream>#include <algorithm>using namespace std;int main(){ ios::sync_with_stdio(false); long long a,b,l,maxn,minn,s,n,low,high,mid; cin>>n; while(n--){ cin>>l>>a>>b; maxn=0; minn=0; if(l&1||l<4){ cout<<0<<endl; continue; }else{ low=0,high=l/4; while(high>=low){ mid=(high+low)/2; if(mid*(l/2-mid)<a){ minn=max(minn,mid); low=mid+1; }else{ high=mid-1; } }// cout<<low<<' '<<mid<<' '<<minn<<' '; low=1,high=l/4; while(high>=low){ mid=(high+low)/2; if(mid*(l/2-mid)<=b){ maxn=max(maxn,mid); low=mid+1; }else{ high=mid-1; } }// cout<<low<<' '<<mid<<' '<<maxn<<' '; cout<<(maxn-minn>0?maxn-minn:0)<<endl; } } return 0;}
阅读全文
0 0
- CSU1204 Rectangles(二分)
- CSU1204-Rectangles-二分
- CSU 1204 Rectangles (二分)
- Rectangles
- Rectangles
- Rectangles
- Rectangles
- Rectangles
- BZOJ 3885 Usaco2015 Jan Cow Rectangles 单调队列+二分
- [Codeforces 333D] Characteristics of Rectangles (二分答案+鸽笼原理)
- 1468 Rectangles
- Rectangles dp
- Packing Rectangles
- Packing Rectangles
- Packing Rectangles
- Packing Rectangles
- Packing Rectangles
- Rectangles 2056
- Golang 页面模板之间的嵌套定义以及静态文件的加载方式
- 通过qemu命令搭建虚拟机环境
- iOS
- C++11系列——函数对象(Function Object)
- Java设计模式之五种单例模式
- CSU1204-Rectangles-二分
- <NOIP> 1 . P1000 超级玛丽游戏
- CSU1209-Three Jugs-GCD
- Redis启动的三种方式
- Kotlin-22.Lambda表达式和函数
- TCP连接的建立和释放(三次握手和四次挥手)
- 【C#】面向对象之多态
- 数据库锁的基本概念
- Bootstrap学习--初识Bootstrap