数论 - 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 ...
随机推荐
- TCP/IP——链路层
链路层主要有三个目的: (1)为IP模块发送和接收IP数据报; (2)为ARP模块发送 ARP请求和接收 ARP应答; (3)为RARP发送RARP请求和接收RARP应答. TCP / IP支持多种不 ...
- TCP中的RST复位信号
TCP中的RST复位信号 在TCP协议中RST表示复位,用来关闭异常的连接,在TCP的设计中它是不可或缺的. 发送RST包关闭连接时,不必等缓冲区的包都发出去,直接就丢弃缓存区的包发送RST包.而接收 ...
- Zabbix3 agent端安装(二)
1.基础环境准备 安装zabbix的yum源,这里有必要提一点,阿里的yum源已经提供了zabbix3.0 1.1.yum源配置 rpm -ihv http://mirrors.aliyun.com/ ...
- vijos1531 食物链
背景 安徽省芜湖市第二十七中学测试题 NOI 2001 食物链(eat) Description:OfficialData:OfficialProgram:JackDavid127 描述 动物王国中有 ...
- mysql登录报错“Access denied for user 'root'@'localhost' (using password: YES”的处理方法
使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码: 文件内容: [client]host = localhostuser = debian-sys-maint ...
- 02第一个OC程序
一.打开XCode4.6.3,新建项目 二.选择Application下的命名行项目 三.输入项目名称,选择Foundation框架创建项目,点击Next 四.二话不说.点击Run.启动我们创建的项目 ...
- jquery 事件委托
什么事件委托? DOM在为页面中的每个元素分派事件时,相应的元素一般都在事件冒泡阶段处理事件.在类似 body > div > a 这样的结构中,如果单击a元素,click事件会从a一直冒 ...
- Java 类初始化顺序
总的来说: 父类静态代码块->子类静态代码块->子类main()方法->父类构造块->父类构造方法->子类构造块->子类构造方法 注意,就算是静态的方法也需要调用才 ...
- [转]关于Android系统的”点九”
李华明Himi原创,转载务必在明显处注明:转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/android-game/321.html 前几天群成员讨论过关 ...
- 前端小知识(转载http://www.cnblogs.com/Wayou/p/things_you_dont_know_about_frontend.html)
前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Quora上一个帖子,瞬间又GET了好多前 ...