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;
    }


  • 相关阅读:
    Java面试知识点总结
    Log4j常用配置及使用
    Eclipse+tomcat+axis2进行web service部署
    iframe内点击a标签禁止滚动到顶部
    VScode首选项
    Bookmarks
    VScode常用插件
    slideout
    bs-loading
    iPhone X 上删除白条
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789479.html
Copyright © 2011-2022 走看看