数论 - Vanya and Computer Game
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai hits.
Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.
Input
The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.
Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.
Output
Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.
Sample Input
4 3 2
1
2
3
4
Vanya
Vova
Vanya
Both
2 1 1
1
2
Both
Both
Hint
In the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.
In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.
--------------------------------------------------------------我是分割线^_^-------------------------------------------------------------------
题意:A,B俩人一起打怪,A一秒打X次,B一秒打Y次,(每个人的攻击是对所有的怪物都有效果),每个怪物被打ai下
就会死掉,问最后一下是谁打的。
解法 :A打一次是1/X 秒 B打一次是1/Y秒,浮点数不好计算,我们把二者乘以XY,那么 A打一次就是Y秒,B打一次就是
X秒。然后二分怪物被打死的时间t.条件是t/X+t/Y>=a。
实际上是比例的问题,题意中A是1/x秒打一次,而B是1/y打一次,比例是1/x :1/y,可以两边都乘以xy,比例化为y:x,
意思是A打一次需要y秒,而B打一次需要x秒,注意乘以之后数据范围的变化,已经超过题目所给的1e9了,所以二分枚举
时间的时候要特别注意这一点= =。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std; #define Int __int64
#define INF 0x3f3f3f3f const int MAXN = 111111;
Int num[MAXN];
Int n, x, y; bool Judge(Int mid, Int m) {
Int s = mid / x + mid / y;
if (s >= m) return true;
else return false;
}
int main()
{
//freopen("input.txt", "r", stdin); while (scanf("%I64d %I64d %I64d", &n, &x, &y) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%I64d", &num[i]);
}
for (int i = 0; i < n; i++) {
Int lower = 1, higher = 1e16;
while (lower <= higher) {
Int mid = (lower + higher) / 2;
bool ok = Judge(mid, num[i]);
if (ok) higher = mid - 1;
else lower = mid + 1;
}
Int s = lower;
if (s % x == 0 && s % y == 0) {
printf("Both\n");
} else if (s % x == 0) {
printf("Vova\n");
} else {
printf("Vanya\n");
}
}
}
return 0;
}
数论 - Vanya and Computer Game的更多相关文章
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分
D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- cf492D Vanya and Computer Game
D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 预处理
D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学
D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- CodeForces 492D Vanya and Computer Game (思维题)
D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces 492D Vanya and Computer Game
D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- 【cf492】D. Vanya and Computer Game(二分)
http://codeforces.com/contest/492/problem/D 有时候感觉人sb还是sb,为什么题目都看不清楚? x per second, y per second... 于 ...
- 【Codeforces 492D】Vanya and Computer Game
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 第一个人攻击一次需要1/x秒 第二个人攻击一次需要1/y秒 这两个数字显然都是小数. 我们可以二分最后用了多少时间来攻击. 显然这个是有单调性 ...
- CodeForces Round #280 (Div.2)
A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...
随机推荐
- yuv420转rgb 及 rgb转bmp保存
/// <summary> /// 将一桢 YUV 格式的图像转换为一桢 RGB 格式图像. /// </summary> /// <param name="y ...
- NAT穿越
1.NAT类型 目前主要的NAT类型有如下几种: 1)Full-cone NAT, also known as one-to-one NAT 一旦一个内网地址 (iAddr:iPort) 被映射到一个 ...
- Android高手速成--第一部分 个性化控件(View)
第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...
- UI第七节——UISlider详解
- (void)viewDidLoad { [super viewDidLoad]; // 实例化UISlider,高度对外观没有影响 UISlider *slider = [[UISlider al ...
- 【荐】PHP Session和Cookie,Session阻塞,Session垃圾回收,Redis共享Session,不推荐Memcached保存Session
什么是 Session 在 web 应用开发中,Session 被称为会话.主要被用于保存某个访问者的数据. 由于 HTTP 无状态的特点,服务端是不会记住客户端的,对服务端来说,每一个请求都是全新的 ...
- ngnix 配置CI框架 与 CI的简单使用
ngnix 支持 CI框架1.修改config.php 参考网址:https://www.chenyudong.com/archives/codeigniter-in-nginx-and-url-re ...
- SqlServer数据库大型应用解决方案总结
随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的互联网应用,每天百万级甚至上亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的问题. 一 ...
- linux各目录的作用
- xmind portable
portable : http://dl2.xmind.cn/xmind-7.5-update1-portable.zip
- ASP.NET基础代码备忘
使用ASP.NET原生的__doPostBack方法触发asp:Button //javaScript部分 __doPostBack('<%=btnAmountDivided.UniqueID ...