A. Vladik and Courtesy

来源:互联网 发布:图片上传到淘宝变模糊 编辑:程序博客网 时间:2024/06/08 11:05

A. Vladik and Courtesy
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 a, b (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
一道简单的思维题,暴力即可,没有任何 的算法。
题目大意:两个人,A有n个糖,B有m个糖,从A开始,A给B一块糖,B给A 2块糖
,依次类推,直到谁没有能力拿出足够的糖。
思路,n-减奇数,m-偶数,没减一次判断是否小于0,若小于0,则输出此人的名称。
代码如下:

#include<cstdio>#include<iostream>using namespace std;int main (){    int n,m;    while(~scanf("%d%d",&n,&m))    {        int i;        for(i=1;;i++)        {            n=n-2*i+1;            if(n<0)            {                printf("Vladik\n");                break;            }            m=m-2*i;            if(m<0)            {                printf("Valera\n");                break;            }        }    }    return 0;}

若有更好的办法,可以留言哦

原创粉丝点击