数论 - 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 ...
随机推荐
- Java递归算法——三角数字(消除递归)
import java.io.*; // for I/O //类名:Params //属性: //方法: class Params //这个类的对象被压入栈中 { public int n; //用来 ...
- 如何在ASP.NET MVC和EF中使用AngularJS
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) AngularJS作为一个越来越流行的前端框架,在使用ASP.NET MVC和实体框架开发W ...
- NPM
参考资料: 淘宝NPM
- windows7安装GitBash和GitGui
安装很简单,搜索安装就行. 配置: 1.$ ssh-keygen -t rsa -C "your_email@youremail.com" 将"your_email@yo ...
- 明晨HOSTS编辑器mcHostsEdtor与火狐HostAdmin配合使用
在开发过程中,需要经常切换环境开发.测试.Stage和正式环境,甚为麻烦. 后来找到了HOST切换工具mcHostsEdtor工具快速切换host,但浏览器比如有HOST缓存,后来同事推荐FireFo ...
- Java实现Excel的操作
JAVA EXCEL API: 开源项目,通过它Java开发人员可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件.使用该API非Windows操作系统也可以通过纯Ja ...
- 【荐】PHP操作MongoDB GridFS 存储文件,如图片文件
GridFS是MongoDB的一个内置功能,它提供一组文件操作的API以利用MongoDB存储文件,GridFS的基本原理是将文件保存在两个Collection中,一个保存文件索引,一个保存文件内容, ...
- URL传递中文字符,特殊危险字符的解决方案(仅供参考)urldecode、base64_encode
很多时候,我们需要在url中传递中文字符或是其它的html等特殊字符,似乎总会有各种乱,不同的浏览器对他们的编码又不一样, 对于中文,一般的做法是: 把这些文本字符串传给url之前,先进行urlenc ...
- 交叉编译中的build、host和target
build.host和target 在交叉编译中比较常见的一些参数就是build.host和target了,正确的理解这三者的含义对于交叉编译是非常重要的,下面就此进行解释 --build=编译 ...
- css动画 animation
今天用css做了一个简单的三角上下移动的一个小动画,说白了就是在改变该物体的height值.除了这个方法,还可以用js. 一.在用css写动画时,一定要记住兼容性问题.如何解决该兼容性?在前面加内核前 ...