Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door Lock
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100500/attachments
Description
It was a beautiful night at Yekaterinburg, the sky was crystal clear with no clouds, and the view of the moon and the stars was magnificent. Coach Fegla was enjoying this view at the Novotel hotel with Hanaa El-Jazzar (a member of the systems operation team of the ACPC). It was the first time for Hanaa to attend the ICPC world finals event, and she was so happy about it and brought coach Fegla a gift from her hometown Lebanon as a sign of gratitude. The gift was a round shaped plate with engraved images of different sightseeing in Lebanon. While Hanaa was showing the present to the coach, two drunk fellows entered the room by mistake. They were so high they could not distinguish their room, from the coach’s room. Coach Fegla thought what if the ones who entered the room were complete strangers, what should he do? He decided to install another lock to his door, but it was not like any other lock. To obtain the key of the lock a certain puzzle has to be solved, this way coach Fegla might be able to stop most of the intruders. The puzzle was as follows, you will be given 2 numbers n and m. You should build up a domino set. Each piece of the set will contain 2 integer numbers in the range from 0 to n-1, and all the pieces are pairwise distinct and no two pieces of domino should look the same if rotated. As you know a domino piece is divided into 2 halves where the top half contains one integer and other half contains the other integer. You should lay down the pieces in a straight line where the top half of each piece should contain the greatest value of the 2 halves. Then you should sort the domino pieces in increasing order based on the top half, in case of equality sort them in increasing order based on the other half. The lock to the key will be the mth piece in this sequence. You will be given n, m can you get lock key? (check the image below for a domino set where n = 3)
Input
The first line will be the number of test cases T. Each of the following lines will contain 2 numbers n, m. 1 ≤ T ≤ 100,000 1 ≤ n ≤ 1,000,000,000 1 ≤ m ≤ n×(n+1) 2
Output
For each test case print a single line containing: Case_x:_a_b x is the case number starting from 1. a is the greatest value on the domino piece, and b is the other value. Replace underscores with spaces.
Sample Input
2 2 1 3 5
Sample Output
Case 1: 0 0 Case 2: 2 1
HINT
题意
让你用两个数来记录这个数的大小,大小记录规则由题目给出
题解:
简单分析之后,发现这其实是一个前缀和的东西,所以我们直接二分就好了
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* int main()
{
int t=read();
for(int cas=;cas<=t;cas++)
{
ll n,m;
n=read(),m=read();
if(m==)
{
printf("Case %d: 0 0\n",cas);
continue;
}
ll l=,r=n;
while(l<r)
{
ll mid=(l+r)/;
if((mid*mid+mid)/>m)
r=mid;
else if((mid*mid+mid)/==m)
l=r=mid;
else
l=mid+;
}
l--,m--;
printf("Case %d: %lld %lld\n",cas,l,m-(l*l+l)/);
}
}
Codeforces Gym 100500F Problem F. Door Lock 二分的更多相关文章
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案
Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342C Problem C. Painting Cottages 转化题意
Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100342C Problem C. Painting Cottages 暴力
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...
- Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
随机推荐
- db2数据库Date相关函数
1.db2可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值. SELECT 'HELLO DB2' FROM SYSIBM ...
- jsoup使用选择器语法来查找元素
问题 你想使用类似于CSS或jQuery的语法来查找和操作元素. 方法 可以使用Element.select(String selector) 和 Elements.select(String sel ...
- echo二次开发 ecshop 函数列表
lib_time.php (时间函数) gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime($h ...
- MySQL索引与优化策略
1. MySQL索引实现 在MySQL中,索引属于存储引擎级别的概念,不同存储引擎对索引的实现方式是不同的,下面主要讨论MyISAM和InnoDB两个存储引擎的索引实现方式. MyISAM索引实现 M ...
- 动态创建WebService
WebService应用主要是为远程提供接口服务,远程通过代理方式获取WebService资源:但是在现实应用过程中,在Web或者应用程序中如果想用生成远程代理,一般是借助vs里提供的 添加-添加we ...
- UVA 10047 The Monocycle
大白图论第二题··· 题意:独轮车的轮子被均分成五块,每块一个颜色,每走过一个格子恰好转过一个颜色. 在一个迷宫中,只能向前走或者左转90度或右转90度(我曾天真的认为是向左走和向右走···),每个操 ...
- JQuery WEB前段开发
JQuery WEB前段开发 Jquery是继prototype之后又一个优秀的Javascript框架.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, S ...
- bzoj 1419 Red is good(期望DP)
[题意] R红B蓝,选红得1选蓝失1,问最优状态下的期望得分. [思路] 设f[i][j]为i个Rj个B时的最优期望得分,则有转移式为: f[i][j]=max{ 0,(f[i-1][j]+1)*(i ...
- Codeforces 377
简单说一下. A 搜索出任意一个剩余细胞个数的联通块.剩下的填X. B 二分加贪心加数据结构. /* * Problem: * Author: Shun Yao */ #include <str ...
- Windows下GNU之gcc体验方法
Windows 现在在Windows下开发C/C++程序一般都是用微软的编译器,当年的Borland已经成为传说.但是如果你不想付钱的话,也可以考虑Windows下的GCC. 在Windows下体验G ...