zoukankan      html  css  js  c++  java
  • [CQOI2013]新Nim游戏

    /**
     * Problem:Nim
     * Author:Shun Yao
     * Time:2013.5.28
     * Result:Accepted
     */
    
    #include <cstdio>
    
    void swap(long &x, long &y) {
    	x ^= y;
    	y ^= x;
    	x ^= y;
    }
    
    int main() {
    	long n, a[100], b[100];
    	freopen("nim.in", "r", stdin);
    	freopen("nim.out", "w", stdout);
    	scanf("%ld", &n);
    	for (long i = 0; i < n; ++i) {
    		scanf("%ld", a + i);
    		b[i] = a[i];
    	}
    	long now = -1;
    	for (long i = 1 << 30; i; i >>= 1) {
    		long pos = -1;
    		for (long j = now + 1; j < n; ++j)
    			if ((a[j] & i) && (pos < 0 || b[j] > b[pos]))
    				pos = j;
    		if (pos < 0)
    			continue;
    		++now;
    		if (pos != now) {
    			swap(a[pos], a[now]);
    			swap(b[pos], b[now]);
    		}
    		for (long j = now + 1; j < n; ++j)
    			if (a[j] & i)
    				a[j] ^= a[now];
    	}
    	long long ans = 0;
    	for (long i = 0; i < n; ++i)
    		if (!a[i])
    			ans += (long long)b[i];
    	printf("%lld", ans);
    	fclose(stdin);
    	fclose(stdout);
    	return 0;
    }
    

     又有错误: 注意c++ &引用 的用法.

  • 相关阅读:
    RSA算法原理(二)
    RSA算法原理(一)
    Diffie-Hellman 算法
    1028:Ignatius and the Princess III
    1014:Uniform Generator
    1013:Digital Roots
    常见OJ评判结果对照表
    Django模板系统
    Django之视图
    Django之路由系统
  • 原文地址:https://www.cnblogs.com/hsuppr/p/3103888.html
Copyright © 2011-2022 走看看