2022CCPC网络预选赛c题Problem C. Guess

原题

Problem C. Guess
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 512 megabytes

Alice and Bob are playing a game. Each of them has a card on his/her forehead with a positive integer written on it(Alice has the integer a and Bob has the integer b).
Alice and Bob can only see their opponent’s number, but both of them know that the two numbers a, b are positive integers and one is twice as large as the other.
Each round, Alice and Bob try to guess their own number in turn, Alice first. (Each round ends when both Alice and Bob finish their tries.)
Both of them are smart enough and they won’t make mistakes. They will speak out the answer if and only if they exactly know it, otherwise, they will say "I don’t know"instead.
Given the two numbers on Alice’s and Bob’s foreheads, find out which round one of them can speak out the integer on his/her forehead.

Input
This problem contains multiple test cases.
The first line contains an integer T indicating the number of test cases (1 ≤ T ≤ 105).
For each test case, the only line contains two integers a, b (1 ≤ a, b ≤ 1018).
It is guaranteed that a = 2b or b = 2a always holds.

Output
For each test case, output two integers r, p indicating at the r-th round, p can speak out the answer. p = 0 stands for Alice and p = 1 stands for Bob.

Example
standard input
3
6 3
1 2
499999999999999999 999999999999999998
standard output
1 0
1 1
1 1

Note
For the first sample, Alice can see the number on Bob’s forehead, which is an odd number 3. Then she can find out that the number on her forehead must be 6 because there is no integer x such that 3 = 2x.
Please notice that: The range of a, b is just for you while the two players don’t know it. That is, when a = 5 × 1017, b = 1018, Alice can’t speak out her number immediately even if a = 2 × 1018 is out of input range.

题目大意

A额头上有一个数字a, B额头上是b, A只能看到b, B只能看到a, 并且已知a是b的两倍或b是a的两倍, 由A开始轮流猜自己额头上的数字, 若不知道就说"I don’t know", 若知道则赢, 输出r和p, 表示到第r轮时p赢, p为0表示A赢, p为1表示B赢.

思路

前提条件a=2b或b=2a

情况1(一奇一偶) :

a和b一个奇数一个偶数.
若a为偶数, 当A看到b为奇数, A就知道自己是b*2, 因为b/2 无法整除;
若a为奇数, 当A看到b为偶数, A无法确定自己是b/2还是b*2, 只能说出"i don’t know", 此时B就知道自己的b是偶数, 当B看到a是奇数, 那么就可以确定自己是a*2了;

情况2(两个都是偶) :

假设a为16, b为32, a含2的因子个数是cnta=4, b含2的因子个数是cntb=5 ;

第一轮:
A:
A无法确定自己是b/2还是b*2, “i don’t know” ;

B:
当A说"i don’t know"时B就可以推出自己是偶数(若自己是奇数A就不会don’t know了) , 即推出自己的b至少含有1个因子2;
此时轮到B, B由a可以推出自己可能是a/2或a*2, 结合"b至少含1个因子2", 判断a/2是否含有1个因子2(a*2肯定是含有1个因子2的, 所以不用往*2考虑, 往/2考虑就行, a/2是否含有1因子2即转化为a是否含有2个因子2), 若有则"i don’t know", 否则B就可以确定自己的b是a*2, 这里a为16, cnta>=2, 所以是"i don’t know";

第二轮:
A:
A由上一轮B的"i don’t konw"可以推出自己的a至少有2个因子2(若a的因子数少于2, 则上一轮B就可能赢了);
此时轮到A, A由b可以推出自己可能是b/2或b*2, 结合"a至少有2个因子2", 判断b/2是否含有2个因子2, 即b是否含有3个因子2, 这里cntb>=3, 所以A只能"i don’t know";

B:
当A说"i don’t know"时B就可以推出自己的b至少含有3个因子2;
此时轮到B, B同理判断a/2是否含有3个因子2, 即判断a是否含有4个因子2, 这里cnta>=4, 所以"i don’t know";

第三轮:
A:
A由上一轮B的"i don’t know"可以推出自己的a至少含有4个因子2;
此时轮到A, A同理判断b/2是否含有4个因子2, 即判断b是否含有5个因子2, 这里cntb>=5, 所以"i don’t know";

B:
B由A的"i don’t know"同理可推出自己的b知识含有5个因子2;
此时轮到B, B同理判断a/2是否含有5个因子2, 即a是否含有6个因子2, 这里cnta<6, 所以B发现a/2不合法, 则b只能等于a*2(a*2含有cnta+1=5个因子2, 符合);
到这里, B赢了;

复杂度为log(n)级别, 可以直接模拟

代码

没保存, 有空再补

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值