【Codeforces 492D】Vanya and Computer Game
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
第一个人攻击一次需要1/x秒
第二个人攻击一次需要1/y秒
这两个数字显然都是小数。
我们可以二分最后用了多少时间来攻击。
显然这个是有单调性的,攻击时间越多的话,攻击的次数也就越多。
假设二分出来攻击的时间是mid
那么攻击的次数就是
mid/(1/x) + mid/(1/y)
但是这样显然二分出来的也是一个小数。
我们完全没有办法根据二分出来的东西判断它到底是谁的倍数。
因此我们可以这样。
我们把第一个人攻击一次和第二个人攻击一次所需要的时间都乘上一个x*y
也就是说我们把秒这个单位换成了自己的一个单位t,而且t = x*y*秒
这样的话,
第一个人攻击一次需要的时间就是y t
第二个人攻击一次需要的时间就是x t
然后我们二分最后需要多少t的时间才够攻击a[i]次。
显然如果二分到mid了
那么攻击次数就是mid/y + mid/x
(如果不够整除的话,显然就已经不够敲一次了,所以向下取整就ok了)
然后根据最后二分出来的t值,如果同时是x和y的倍数的话,就是both,否则根据%x和%y的结果的出来最后一次是谁敲的就好了。
(这样涉及到的运算就都是整数的了)
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5;
ll n,x,y;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> x >> y;
while (n--){
ll cnt;
cin >> cnt;
ll l = 1,r = 1e16,temp = -1;
while (l<=r){
ll mid = (l+r)/2;
if (mid/y+mid/x>=cnt){
temp = mid;
r = mid - 1;
}else l = mid + 1;
}
if (temp%y==0 && temp%x==0){
cout<<"Both"<<endl;
}else if (temp%y==0){
cout<<"Vanya"<<endl;
}else {
cout<<"Vova"<<endl;
}
}
return 0;
}
【Codeforces 492D】Vanya and Computer Game的更多相关文章
- 【39.29%】【codeforces 552E】Vanya and Brackets
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【25.33%】【codeforces 552D】Vanya and Triangles
time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- 【30.23%】【codeforces 552C】Vanya and Scales
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【33.33%】【codeforces 552B】Vanya and Books
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【84.62%】【codeforces 552A】Vanya and Table
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【12.78%】【codeforces 677D】Vanya and Treasure
time limit per test1.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【13.77%】【codeforces 734C】Anton and Making Potions
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 762B】USB vs. PS/2
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- JavaScript--DOM创建元素节点createElement
创建元素节点createElement createElement()方法可创建元素节点.此方法可返回一个 Element 对象. 语法: document.createElement(tagName ...
- 2017 JUST Programming Contest 3.0 K. Malek and Summer Semester
K. Malek and Summer Semester time limit per test 1.0 s memory limit per test 256 MB input standard i ...
- 题解报告:hdu 1541 Stars(经典BIT)
Problem Description Astronomers often examine star maps where stars are represented by points on a p ...
- Linux单机环境下HDFS伪分布式集群安装操作步骤v1.0
公司平台的分布式文件系统基于Hadoop HDFS技术构建,为开发人员学习及后续项目中Hadoop HDFS相关操作提供技术参考特编写此文档.本文档描述了Linux单机环境下Hadoop HDFS伪分 ...
- Normal equations 正规方程组
前面我们通过Gradient Descent的方法进行了线性回归,但是梯度下降有如下特点: (1)需要预先选定Learning rate: (2)需要多次iteration: (3)需要Feature ...
- java_dom4j解析xml
package forRQ; import java.io.File;import java.net.MalformedURLException;import java.util.Iterator;i ...
- c语言-依赖倒转
当一个文件(aa.c文件)依赖于头文件(bb.h)时,如果bb.c编译之后形成的bb.o文件重新编译后,aa.o的文件不需要重新编译 aa.c文件: bb.h文件:对bb.c文件进行声明 bb.c文件 ...
- 微信小程序开发初次尝试-----实验应用制作(一)
初次尝试微信小程序开发,在此写下步骤以做记录和分享. 1.在网上找了很多资料,发现这位知乎大神提供的资料非常全面. 链接 https://www.zhihu.com/question/50907897 ...
- e.Row.RowType == DataControlRowType.DataRow详解(转)
代码语句如下: protected void OnRowCreate(object sender, GridViewRowEventArgs e) { if (e.Row.RowT ...
- linux下安装xampp
Choose your flavor for your linux OS, the 32-bit or 64-bit version. Change the permissions to the in ...