题目网址:点击打开链接
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.
Single line of input data contains two space-separated integers a, b (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
1 1
Valera
7 6
Vladik
Illustration for first test case:

Illustration for second test case:

很简单,模拟这个过程就行。
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
int s=1;
while(1)
{
if(a-s<0)
{
printf("Vladik\n");break;
}
else
{
a-=s;
s++;
}
if(b-s<0)
{
printf("Valera\n");break;
}
else
{
b-=s;s++;
}
}
return 0;
}
本文介绍了一个简单的编程问题,即两个参与者轮流互相交换递增数量的糖果,直到一方无法继续为止。文章提供了一段C语言代码,该代码通过模拟过程确定了哪一方会首先无法继续进行交换。
438

被折叠的 条评论
为什么被折叠?



