Problem F. Door Lock
Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
Http://codeforces.com/gym/100500/attachments
Description
It is a beautiful night at Yekaterinburg, the sky is crystal clear with no clouds, and the view of the moon and the star S was magnificent. Coach Fegla is enjoying this view on the Novotel hotel with Hanaa El-jazzar (a member of the systems operation team of TH e acpc). It is the first time for Hanaa to attend the ICPC World Finals event, and she is so happy about it and brought coach Feg La a gift from she hometown Lebanon as a sign of gratitude. The gift is a round shaped plate with engraved images of different sightseeing in Lebanon. While Hanaa is showing the present to the coach, and the other drunk fellows entered the hostel by mistake. They were so-they could not distinguish-their, from the coach's ' s. Coach Fegla thought what if the ones who entered the the-the-were, what strangers he does? He decided to the install another lock to his door, but it is not a like any other lock. To obtain the key of the lock a certain puzzle have to is solved, this is the coach Fegla might Be-able to stop most of the intruders. The puzzle is as follows, you'll be given 2 numbers n and M. You should build up a domino set. Each piece of the set would contain 2 integer numbers in the range from 0 to n-1, and all the pieces is pairwise distinct And no pieces of domino should look the same if rotated. As you know a domino piece is divided to 2 halves where the top half contains one integer and other half contains the OT Her integer. You should lay down the pieces with a straight line where the top half of each piece should contain the greatest value of th E 2 halves. Then your should sort the domino pieces in increasing order based on the top half, in case of equality sort them in Increas ING order based on the other half. The lock to the key would be the mth piece in this sequence. You'll be given n, M can you get lock key? (Check the image below for a domino set where n = 3)
Input
The first line would be the number of test cases T. Each of the following lines would contain 2 numbers n, M. 1≤t≤100,000 1≤n≤1,000,000,000 1≤m≤nx (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 are 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
Test instructions
Let you use two numbers to record the size of this number, the size of the record rule by the question given
The following:
After a simple analysis, it turns out that this is actually a prefix and something, so we're just going to split it up.
Code
#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************intMain () {intt=read (); for(intcas=1; cas<=t;cas++) {ll n,m; N=read (), m=read (); if(m==1) {printf ("Case %d:0 0\n", CAs); Continue; } ll L=0, r=N; while(l<R) {ll mid= (l+r)/2; if((Mid*mid+mid)/2>m) r=mid; Else if((Mid*mid+mid)/2==m) L=r=mid; ElseL=mid+1; } l--, m--; printf ("Case %d:%lld%lld\n", cas,l,m-(l*l+l)/2); }}
Codeforces Gym 100500F problem F. Door Lock two points