Codeforces 492D - Vanya and Computer Game (二分)

来源:互联网 发布:php建站模板 编辑:程序博客网 时间:2024/05/28 15:07

题意

一只怪兽要被打X下才死,两个人的攻击频率各不同,求怪兽被谁打死。

思路

相当于第一个人y秒打一下,第二个人x秒打一下。

只要得知怪兽在第几秒被打死,就知道是被谁打死的。所以二分答案,得到怪兽惨死的时间,然后判断即可。

代码

  1. #include <cstdio>
  2. #include <iostream>
  3. using namespace std;
  4. const long long MAXN = 1e11 + 100;
  5. int main()
  6. {
  7. ios::sync_with_stdio(0);
  8. long long fx, fy, n;
  9. cin >> n >> fx >> fy;
  10. for (int i = 0; i < n; i++)
  11. {
  12. long long tmp, ans;
  13. cin >> tmp;
  14. long long l = 0, r = 1e15, mid;
  15. while (l <= r)
  16. {
  17. mid = (l + r) >> 1;
  18. if (mid / fx + mid / fy >= tmp)
  19. {
  20. ans = mid;
  21. r = mid - 1;
  22. }
  23. else l = mid + 1;
  24. }
  25. if (ans % fx == 0 && ans % fy == 0) cout << "Both" << endl;
  26. else if (ans % fy) cout << "Vova" << endl;
  27. else cout << "Vanya" << endl;
  28. }
  29. return 0;
  30. }
0 0
原创粉丝点击