数论 - 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 ...
随机推荐
- iframe子页面点击按钮,执行父页面的点击事件
iframe 子页面点击.parent 父页面 的id(auth-link-btn)的事件 <a href="javascript:void(0);" onclick=&q ...
- QT中检索设定目录下所有指定文件的方法
void MainWindow::on_pushButton_clicked() { QDir dir=QFileDialog::getExistingDirectory(this, tr(" ...
- ThinkPHP配置简单的mysql读写分离
ThinkPHP内置了分布式数据库的支持,包括主从式数据库的读写分离,但是分布式数据库必须是相同的数据库类型. 配置DB_DEPLOY_TYPE 为1 可以采用分布式数据库支持.如果采用分布式数据库, ...
- 搭建XMPP学习环境
XMPP(Extensible Messaging and Presence Protocol,前称Jabber)是一种以XML为基础的开放式IM协议.xmpp被人熟知,google talk肯定有一 ...
- java表格操作之设置表格列宽
设置所有列的宽度 /** * 设置所有列的列宽 * @param table * @param width */ public void setAllColumnWidth(JTable table, ...
- Linux进程间通信(四):命名管道 mkfifo()、open()、read()、close()
在前一篇文章—— Linux进程间通信 -- 使用匿名管道 中,我们看到了如何使用匿名管道来在进程之间传递数据,同时也看到了这个方式的一个缺陷,就是这些进程都由一个共同的祖先进程启动,这给我们在不相关 ...
- 使用ajax技术实现txt弹出在页面上
使用ajax技术实现txt弹出在页面上 使用ajax技术实现点击按钮,将TXT文本里的内容通过弹出框显示到页面上 /*事件会在页面加载完成后触发.*/ <script> window. ...
- javascript基础05
javascript基础05 1.变量的作用域 变量既可以是全局,也可以是局部的. 全局变量:可以在脚本中的任何位置被引用,一旦你在某个脚本里声明了全局变量,你就可以 在这个脚本的任何位置(包括函数内 ...
- QuickSort 快速排序 基于伪代码实现
本文原创,转载请注明地址 http://www.cnblogs.com/baokang/p/4737492.html 伪代码 quicksort(A, lo, hi) if lo < hi p ...
- Android 全局获取 Context 与使用 Intent 传递对象
=====================全局获取 Context======================== Android 开发中很多地方需要用到 Context,比如弹出 Toast.启动活 ...