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 二分的更多相关文章

  1. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  5. Codeforces Gym 100342C Problem C. Painting Cottages 转化题意

    Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  6. Codeforces Gym 100342C Problem C. Painting Cottages 暴力

    Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...

  7. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  8. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

  9. Codeforces Gym 100610 Problem E. Explicit Formula 水题

    Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

随机推荐

  1. MyBatis学习 之 三、动态SQL语句

    目录(?)[-] 三动态SQL语句 selectKey 标签 if标签 if where 的条件判断 if set 的更新语句 if trim代替whereset标签 trim代替set choose ...

  2. 为在MyEclipse中配置Tomcat服务器郁闷的朋友们解决郁闷

    是不是很郁闷!为了在MyEclipse配置Tomcat 服务器,竟然弄了你几乎一个上午,最后也没弄成功,也许你本该早注意到Tomcat 5.x要有这个JDK的支持,配置才能成功. 一上午辛辛苦苦也没解 ...

  3. 【c++内存分布系列】单继承

    父类包括成员函数.静态函数.静态方法,子类包括成员函数.静态函数.静态方法的情况与一个类时完全一致,这里就不做分析了.子类单独包含虚函数时继承无关,也不做分析了. 一.父类子类都为空 #include ...

  4. asp.net MVC 应用程序的生命周期(上)

    首先我们知道http是一种无状态的请求,他的生命周期就是从客户端浏览器发出请求开始,到得到响应结束.那么MVC应用程序从发出请求到获得响应,都做了些什么呢? 本文我们会详细讨论MVC应用程序一个请求的 ...

  5. java jvm学习笔记十二(访问控制器的栈校验机制)

    欢迎装载请说明出处:http://blog.csdn.net/yfqnihao 本节源码:http://download.csdn.net/detail/yfqnihao/4863854 这一节,我们 ...

  6. Dubbo入门实例--转载

    原文地址:http://blog.csdn.net/ruishenh/article/details/23180707?utm_source=tuicool 1.   概述 Dubbo是一个分布式服务 ...

  7. 对delegate进行扩展 打造通用的"计时完成"方法 z

    让用户尽量少打字 每次让用户输入这么多信息的确很糟糕, 可以改进一下设计: 服务器IP和用户名可以存放在配置文件里面, 初始化的时候默认加载到相应的文本框中; 从安全角度考虑, 密码必须经过用户手动输 ...

  8. .net 接口返回json格式示例

    1.新建 InterfaceTestPro1 项目: FILE - New - Project... - Web - ASP.NET Web Forms Application name:Interf ...

  9. POI 读取Excel文档中的数据——兼容Excel2003和Excel2007

    Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. HSSF - 提供读写Microsoft Exce ...

  10. 【暑假】[基本数据结构]根据BFS与DFS确定树

    UVa10410 Tree Reconstruction 算法:根据BFS构造pos数组以区分关系,在此基础上对DFS序列操作.注:栈中存父结点,栈顶是最优先的父结点. 代码如下: #include& ...