codeforces 492D Vanya and Computer Game(额。。。数学题?水题吧)

来源:互联网 发布:ubuntu怎么编辑文件 编辑:程序博客网 时间:2024/05/19 18:45

传送门:点击打开链接


题目大意:

有2个人在打怪,攻击频率分别是x,y。小怪有num点血。问死的时候是谁打死的。如果同时出手 输出Both。


解题思路:

在一秒内考虑这个问题(一秒是循环节)。

假设攻击时刻的分母x*y。那么容易得到每个人的攻击时刻(在一秒内)。

然后如果有一个时刻有重复。那么肯定是2个人同时在打。

排个序就好了。


这是D题么。。。我觉得最多是C题难度,吐槽一下。。。


#include <cstdio>#include <vector>#include <iostream>#include <algorithm>#include <cstring>using namespace std;struct Node{    long long num;    int team;    bool operator < (const Node& b)const{        return num < b.num;    }}a[2020202];int cnt;void init(long long x,long long y){    cnt = 0;    for(int i = 1;i <= x;i++){        a[cnt++] = (Node){(long long)(y*i),1};    }    for(int i = 1;i <= y;i++){        a[cnt++] = (Node){(long long)(x*i),2};    }}int main(){    int n;    long long x,y;    cin >> n >> x >>y;    init(x,y);    sort(a,a+cnt);    for(int i = 1;i <= n;i++){        long long times;        scanf("%I64d",×);        times--;        times = times%(x+y);        if(times+1 < cnt && a[times].num == a[times+1].num){            printf("Both\n");            continue;        }        if(times != 0 && a[times].num == a[times-1].num){            printf("Both\n");            continue;        }        if(a[times].team == 1){            printf("Vanya\n");        }        else{            printf("Vova\n");        }    }    return 0;}


0 0