Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
来源:互联网 发布:淘宝邪气鞍座封号吗 编辑:程序博客网 时间:2024/05/17 08:34
思路:由于hit的时间涉及浮点数,处理起来较繁琐,所以可以换一种思路。由于所有的monster同时被attack,所以处理1s内的情况即可。预处理一秒内两个人的hit顺序,若同时hit则记为BOTH。
预处理hit次序只需按次数进行扫描,设当前VANYAhit次数为hit_x,VOVA为hit_y,则VANYA的下一次hit时刻为(hit_x + 1)/x,VOVA的下一次hit时刻为(hit_y + 1)/y
①next_x < next_y,说明最近的hit时刻属于VANYA,则此次攻击记录VANYA,hit_x ++
②next_x > next_y,说明最近的hit时刻属于VOVA,则此次攻击记录VOVA,hit_y ++
③next_x = next_y,说明最近的hit时刻两人同时攻击,这两次攻击都记录BOTH,hit_x ++ hit_y++
一秒内hit总和为x+y,所需时间为O(x+y)
代码如下:
#include <cstdio>#include <algorithm>using namespace std;#define N 2000005#define VANYA 0#define VOVA 1#define BOTH 2int sta[N], a[100005];char ans[3][6] = {"Vanya", "Vova", "Both"};int main(){int n, x, y;scanf("%d %d %d", &n, &x, &y);for(int i = 0; i < n; ++i)scanf("%d", &a[i]);int hit_x = 0, hit_y = 0, idx = 0, total = x + y;while(hit_x < x && hit_y < y){double next_x = (double)(hit_x + 1) / x, next_y = (double)(hit_y + 1) / y;if(next_x < next_y)sta[idx] = VANYA, hit_x ++;else if(next_x > next_y)sta[idx] = VOVA, hit_y ++;elsesta[idx] = BOTH, sta[++idx] = BOTH, hit_x ++, hit_y ++; ++idx;}for(int i = 0; i < n; ++i){int last = (a[i] - 1) % total;printf("%s\n", ans[sta[last]]);}return 0;}
0 0
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
- Codeforces Round #280 (Div. 2)-D. Vanya and Computer Game
- Codeforces #280 (Div. 2)D Vanya and Computer Game
- Codeforces Round #280 (Div. 2)D. Vanya and Computer Game(二分)
- Codeforces #280 (Div. 2)D Vanya and Computer Game (二分 + 模拟)
- CodeForces 492D Vanya and Computer Game
- Codeforces 492D Vanya and Computer Game
- CodeForces 492D Vanya and Computer Game
- Codeforces 492D Vanya and Computer Game
- codeforces 492D. Vanya and Computer Game
- D - Vanya and Computer Game
- D. Vanya and Triangles(Codeforces Round #308 (Div. 2))
- Codeforces Round #308 (Div. 2) D. Vanya and Triangles
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure
- Codeforces Round #355 (Div. 2) D. Vanya and Treasure
- Codeforces Round #355 (Div. 2)D. Vanya and Treasure
- Codeforces Round #308 (Div. 2) D Vanya and Triangles
- Codeforces Round #280 (Div. 2)---B. Vanya and Lanterns (贪心 + 预处理)
- android的消息处理机制(图+源码分析)——Looper,Handler,Message
- window.location.href后面的url带多个参数
- LeetCode—— Binary Tree Traversal
- voltDB探索工具
- Java设计模式(一) 之 详解单例模式
- Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学+预处理
- Android INSTALL_FAILED_UID_CHANGED
- ATL/COM----IDL和MIDL之详解
- iphone的系统信息使用[UIDevice currentDevice]
- hdu5305Friends dfs
- mysql进阶(四)mysql中select
- HttpUtil的小错误
- IOS 图片折叠效果实现
- db2中的with用法,可以实现循环累加