zoukankan      html  css  js  c++  java
  • CodeForces

    //有一句话很容易忽视入坑,"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;
    }


  • 相关阅读:
    MFC对话框控件数据提取之DoDataExchange()
    慎用USES_CONVERSION
    Oracle OCP 11G 051(61题版本)答案解析目录
    OCP-1Z0-新051-61题版本-61
    OCP-1Z0-新051-61题版本-60
    OCP-1Z0-新051-61题版本-59
    OCP-1Z0-新051-61题版本-58
    OCP-1Z0-新051-61题版本-57
    OCP-1Z0-新051-61题版本-55
    OCP-1Z0-新051-61题版本-56
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789479.html
Copyright © 2011-2022 走看看