zoukankan      html  css  js  c++  java
  • codeforces 811A Vladik and Courtesy

    A. Vladik and Courtesy
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.

    More formally, the guys take turns giving each other one candy more than they received in the previous turn.

    This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.

    Input

    Single line of input data contains two space-separated integers ab (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively.

    Output

    Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.

    Examples
    input
    1 1
    output
    Valera
    input
    7 6
    output
    Vladik
    Note

    Illustration for first test case:

    Illustration for second test case:

    题意:Vladik和Valera分别有a和b个糖,然后从Vladik开始拿1个,然后轮到Valera拿2个,然后Vladik开始拿3个,然后轮到Valera拿4个.。。。。。最后谁不能拿输出谁

    分析:数据范围1e9,直接暴力i从1开始,奇数a=a-i,偶数b=b-i,谁小于0输出名字,break;

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     long long a,b;
     7     cin>>a>>b;
     8     for(int i=1;i<=10000007;i++){
     9         if(i%2==1){
    10             a=a-i;
    11             if(a<0) {cout<<"Vladik"<<endl;break;}
    12         }
    13         else{
    14             b=b-i;
    15             if(b<0) {cout<<"Valera"<<endl;break;}
    16         }
    17     }
    18     return 0;
    19 }
    View Code
  • 相关阅读:
    四人过桥求最短时间(《算法设计与分析》习题一的第8题) Apare_xzc
    已知中序后序遍历还原二叉树(uva 548) Apare_xzc
    大二下学期第四周周报(2019.3.24) Apare_xzc
    大二下学期第五周周报(2019.3.31) Apare_xzc
    拓扑排序复习(处女座的比赛资格)
    exgcd复习 Apare_xzc
    ACM课程设计课 Advance_Contest_1 解题报告 Apare_xzc
    使用共享内存
    使用信号量
    使用命名管道
  • 原文地址:https://www.cnblogs.com/ls961006/p/6914834.html
Copyright © 2011-2022 走看看