zoukankan      html  css  js  c++  java
  • [CF15C]Industrial Nim

    题目大意:有$n$个采石场,每行一个$m_i$一个$x_i$,表示第$i$个采石场有$m_i$辆车,这个采石场中车中的石子为从$x_i$开始的自然数。Nim游戏若先手赢输出"tolik",后手赢输出"bolik"。

    题解:Nim游戏,可以发现连续的四个自然数且第一个数可被4整除,那么它们的异或值为0

    卡点:1.未考虑$m_i < 4$的情况

      2.未考虑$x_i < 4$的情况

    C++ Code:

    #include <cstdio>
    #define int long long
    using namespace std;
    int n, x, m, ans;
    inline int min(int a, int b) {return a < b ? a : b;}
    int calc(int x) {
    	int tmp = x % 4;
    	if (!tmp) return x;
    	else if (tmp == 1) return 1;
    		else if (tmp == 2) return x + 1;
    			else if (tmp == 3) return 0;
    }
    int run(int x, int m) {
    	return calc(x - 1) ^ calc(x + m - 1);
    }
    //int run(int x, int m) {
    //	int tmp = (x - 1) / 4 + 1, res = 0;
    //	for (int i = x; i < min(x + m, tmp * 4); i++) res ^= i;
    //	tmp = (x + m - 1) / 4;
    //	for (int i = tmp * 4; i <= x + m - 1; i++) res ^= i;
    //	return res;
    //}
    signed main() {
    	scanf("%lld", &n);
    	while (n--) {
    		scanf("%lld%lld", &x, &m);
    		ans ^= run(x, m);
    	}
    	if (ans) puts("tolik");
    	else puts("bolik");
    	return 0;
    }
    

      

  • 相关阅读:
    最长公共子序列
    BFS 从起始点到目标点的最短步数
    熟悉的A+B
    跳格子 完全背包
    pccontrol_scr
    VB快速读取TextBox第N行的数据 (转载)
    日语初学者会话
    语法着色控件使用典型范例
    2008年日语3级真题
    纯api实现ping主机(仅仅返回是否ping通)
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/9355388.html
Copyright © 2011-2022 走看看