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. border-radius 在安卓手机竟然不完美支持

    如果给图片加了width:50px;height:50px;border-radius:25px;-webkit-border-radius:25px;border:3px solid #fff; 在 ...

  2. 【转】android Apk打包过程概述_android是如何打包apk的

    最近看了老罗分析android资源管理和apk打包流程的博客,参考其他一些资料,做了一下整理,脱离繁琐的打包细节和数据结构,从整体上概述了apk打包的整个流程.   流程概述: 1.打包资源文件,生成 ...

  3. 【原创】利用Windows系统日志统计员工每天上下班考勤时间

    利用Windows系统日志统计员工每天上下班考勤时间(命令行参数为统计月份): using System; using System.Collections.Generic; using System ...

  4. java web 学习十三(使用session防止表单重复提交)

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...

  5. Storm入门教程 第三章Storm集群安装部署步骤、storm开发环境

    一. Storm集群组件 Storm集群中包含两类节点:主控节点(Master Node)和工作节点(Work Node).其分别对应的角色如下: 主控节点(Master Node)上运行一个被称为N ...

  6. Android中ListView中有button,checkbox,GridView时事件问题

    最近做项目,用到了listview的item的一些问题,现在抽空把它们总结一下: 转载请表明出处:http://blog.csdn.net/wdaming1986/article/details/67 ...

  7. HDU5697 刷题计划 dp+最小乘积生成树

    分析:就是不断递归寻找靠近边界的最优解 学习博客(必须先看这个): 1:http://www.cnblogs.com/autsky-jadek/p/3959446.html 2:http://blog ...

  8. [Irving]字符串相似度-字符编辑距离算法(c#实现)

    编辑距离(Edit Distance),又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的最少编辑操作次数.许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字 ...

  9. 浅谈javascript的变量作用域

    1.变量遵循先声明再使用. console.log(b); b=123; 代码运行结果: Uncaught ReferenceError: b is not defined 2.方法内定义的局部变量外 ...

  10. Asp.net TextBox常规输入验证

    Asp.net TextBox只能输入数字<asp:textbox id="TextBox1" onkeyup="if(isNaN(value))execComma ...