Codeforces 492D Vanya and Computer Game
2 seconds
256 megabytes
standard input
standard output
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.
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.
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.
4 3 2
1
2
3
4
Vanya
Vova
Vanya
Both
2 1 1
1
2
Both
Both
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%(x+y)是谁打的就得到了正确答案了。
因为前面的时间两个人打得枪数都是固定了的。
那么预处理(x+y)枪(用整数处理就好了,直接用double的话有浮点误差),
标记一下是谁射的,然后进行排序。
O(1)看一下 a%(x+y) 是谁射的,看一下前后有没有相同时间不同人射的。
然后就可以弄出答案来了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm> using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;
const int N = ;
const int M = ;
const int inf = 1e9+;
#define X first
#define Y second
LL n , x , y , a ;
vector<pii>e;
void Run() {
e.clear();
for( int i = ; i <= x ; ++i ) e.push_back( pii( y*i , ) );
for( int i = ; i <= y ; ++i ) e.push_back( pii( x*i , ) );
sort( e.begin() , e.end() ) ;
for( int i = ; i < n ; ++i ) {
cin >> a ;
LL s = a / ( x + y ) ;
if( s * ( x + y ) < a ) a -= s * ( x + y ) ;
else a = x + y ;
a--;
if( a < x + y && e[a].X == e[a+].X ) { cout << "Both" << endl ; continue ; }
if( a > && e[a].X == e[a-].X ) { cout << "Both" << endl ; continue ; }
if( e[a].Y == ) { cout << "Vanya"<<endl; continue ; }
cout << "Vova" <<endl;
}
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
while( cin >> n >> x >> y ) Run();
}
Codeforces 492D Vanya and Computer Game的更多相关文章
- 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 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 ...
- 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 ...
- 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 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...
- Codeforces 677D Vanya and Treasure 暴力+BFS
链接 Codeforces 677D Vanya and Treasure 题意 n*m中有p个type,经过了任意一个 type=i 的各自才能打开 type=i+1 的钥匙,最初有type=1的钥 ...
- [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)
[Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...
- 【Codeforces 492D】Vanya and Computer Game
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 第一个人攻击一次需要1/x秒 第二个人攻击一次需要1/y秒 这两个数字显然都是小数. 我们可以二分最后用了多少时间来攻击. 显然这个是有单调性 ...
随机推荐
- YARN的伪分布式安装
前提:安装完HDFS以后 1.修改mapred-site.xml 这个文件初始时是没有的,有的是模板文件,mapred-site.xml.template 所以需要拷贝一份,并重命名为mapred-s ...
- openstack stein部署手册 2. 基础应用
1. chrony # 安装程序包 yum install -y chrony # 变更配置文件 /etc/chrony.conf 增加 server 192.168.123.200 iburst # ...
- 8VC Venture Cup 2017 - Elimination Round - C
题目链接:http://codeforces.com/contest/755/problem/C 题意:PolandBall 生活在一个森林模型的环境中,定义森林由若干树组成,定义树为K个点,K-1条 ...
- foreach与正常for循环效率对比
foreach foreach编译成字节码之后,使用的是迭代器实现的. foreach特点: 无须获取容器大小 需要创建额外的迭代器变量 遍历期间得到的是对象,没有索引位置信息,因此不能进行赋值操作. ...
- HDU-5378 概率DP
题意:给定一棵有n个节点的树,现在要给节点附1~n的权值(各节点权值不能相同),一棵子树的领袖就是子树中权值最大的节点,问有多少种分配方案使得最后有恰好K个领袖. 解法:这道题一看以为是树上的计数问题 ...
- linux下载网页上的文件夹以及删除文件(stream)
wget -nd -r -l1 --no-parent http://www.cs.virginia.edu/stream/FTP/Code/ 注:-nd 不创建目录:-r 递归下载:-l1只下载当前 ...
- 不在同一个解决方案下的exe去调试dll,采用附加到进程:
先把dll的项目生成一下,把得到的pdb,dll文件复制到exe目录下,然后直接双击运行exe(不是通过vs启动),再接着在dll的项目中”调试”->”附加到进程”,选择刚才运行的exe. 注意 ...
- SpringBoot---Servlet容器(Tomcat)配置
1.概述 1.1.Tomcat所有属性 都在org,springframework.boot.autoconfigure.web.ServerProperties配置类中作了定义: 2.替换Tomc ...
- Syntax behind sorted(key=lambda :)
I think all of the answers here cover the core of what the lambda function does in the context of so ...
- js-放大镜效果
jd或者淘宝的具体商品有个放大镜的效果.虽然网上类似插件琳琅满目,应用到项目上有诸多不便,自己抽点时间自己写了个类似插件,积累下代码,何乐而不为呢!!let‘go: 打算把此特效封装成个插件,先把最基 ...