CodeForces - 811A Vladik and Courtesy

//有一句话很容易忽视入坑,"Candies, which guys got from each other, they don't consider as their own."
//他们并不把对方给的,当作是自己的,相当于只是做减法,不必做加法,一开始审题不清,忽视了,导致WA了几次... T^T 
//我是通过tp初值置为0,每次循环tp = 1- tp,来实现标记哪个人在给对方糖,还可通过循环变量的奇偶性判断,见法二
#include <bits/stdc++.h>
using namespace std;
int ifillegal(int a)
{
	return (a < 0) ? 1:0;
}
int main()
{
	string str[2] = {"Vladik", "Valera"};
	int a, b;
	while (cin >> a >> b)
	{
		int give = 1, tp = 0;
		for (; ; tp = 1 - tp, give++)
		{
			if (!tp) //tp == 0,前者给后者 
			{
				a -= give;
			//	b += give;
				if (ifillegal(a)) break;
			}
			else
			{
				b -= give;
		//		a += give;
				if (ifillegal(b)) break;
			}
		}
		cout << str[tp] << endl;
	}
	return 0;
}



//技巧运用:这个是通过i的奇偶性,判断是谁给糖
// &1 代替 %2(位运算的巧用)
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, i;
	cin >> a >> b;
	int n = max(a, b);
	
	for (i = 1; ; i++)
	{
		if (i & 1)
		{
			if ( a >= i ) a -= i;
			else break;
		}
		else
		{
			if ( b >= i ) b -= i;
			else break;
		}
	}
	if (i & 1) cout << "Vladik" << endl;
	else cout << "Valera" << endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值