Codeforces 492D Vanya and computer Game cycle section finding patterns

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions

The amount of blood given n monsters, X ', y

The first person attacks X times per second, and the second attacks Y times per second.

Each attack causes a bit of damage to all surviving monsters.

Ask each monster who killed the last blow.

Idea: xy least common multiple inside a cycle section, first run out of this cycle section (while the attack caused 2 damage, just add 2 times in the cycle section both)

And then for every freak, just care about which attack point is in the Loop section.


#include <bits/stdc++.h>using namespace Std;const int maxn=2000010;int v[maxn];int main () {    long long n,x,y;    cin>>n>>x>>y;    int sum=0;    for (int i=1,j=1;i<=y&&j<=x;)    {        if (i*x<j*y) {v[++sum]=2;i++;continue;}        if (i*x>j*y) {v[++sum]=1;j++;continue;}        if (i*x==j*y) {v[++sum]=0;v[++sum]=0;i++;j++;continue;}    }    Long long m=x*y;    for (int i=0;i<n;i++)    {        long long A;        cin>>a;        A=a%sum;        if (v[a]==1) {cout<< "Vanya" <<endl;continue;}        if (v[a]==2) {cout<< "Vova" <<endl;continue;}        if (v[a]==0) {cout<< "Both" <<endl;continue;}    }    return 0;}


Codeforces 492D Vanya and computer Game cycle section finding patterns

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.