-
Notifications
You must be signed in to change notification settings - Fork 2
/
CRDGAME3.cpp
67 lines (49 loc) · 2.38 KB
/
CRDGAME3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Chef is playing a card game with his friend Rick Sanchez. He recently won against Rick's grandson Morty; however, Rick is not as easy to beat. The rules of this game are as follows:
The power of a positive integer is the sum of digits of that integer. For example, the power of 13 is 1+3=4.
Chef and Rick receive randomly generated positive integers. For each player, let's call the integer he received final power.
The goal of each player is to generate a positive integer such that its power (defined above) is equal to his final power.
The player who generated the integer with fewer digits wins the game. If both have the same number of digits, then Rick cheats and wins the game.
You are given the final power of Chef PC and the final power of Rick PR. Assuming that both players play optimally, find the winner of the game and the number of digits of the integer he generates.
Input
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first and only line of each test case contains two space-separated integers PC and PR.
Output
For each test case, print a single line containing two space-separated integers. The first of these integers should be either 0 if Chef wins or 1 if Rick wins. The second integer should be the number of digits of the integer generated by the winner.
Constraints
1≤T≤105
1≤PC,PR≤106
Subtasks
Subtask #1 (100 points): original constraints
Example Input
3
3 5
28 18
14 24
Example Output
1 1
1 2
0 2
Explanation
Example case 1: Chef and Rick generate the optimal integers 3 and 5 respectively. Each of them has 1 digit, so Rick cheats and wins the game.
Example case 2: Chef and Rick could generate e.g. 6877 and 99 respectively. Since Rick's integer has 2 digits and Chef cannot generate an integer with less than 4 digits, Rick wins.
Example case 3: Chef and Rick could generate e.g. 86 and 888 respectively. Chef's integer has 2 digits and Rick cannot generate an integer with less than 3 digits, so Chef wins.
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
long pc, pr;
cin>>pc>>pr;
int c=ceil(float(pc)/9);
int r=ceil(float(pr)/9);
if(r<=c) cout<<"1 "<<r<<endl; // rick wins
else cout<<"0 "<<c<<endl; // chef wins
}
return 0;
}