zoukankan      html  css  js  c++  java
  • POJ

    模型是个线性模2方程组。高斯消元的话可能解不唯一,要找独立变元。

    但是不难看出,枚举左端点按下的状态,之后可以影响端点就只有一个变量了,根据端点递推了,然后检查。(写的时候想的是枚举左右端点

    /*********************************************************
    *            ------------------                          *
    *   author AbyssalFish                                   *
    **********************************************************/
    #include<cstdio>
    #include<iostream>
    #include<string>
    #include<cstring>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<vector>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<cmath>
    #include<numeric>
    using namespace std;
    
    const int N = 20;
    int b[N];
    
    
    //#define LOCAL
    int main()
    {
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
    #endif
        for(int i = 0; i < N; i++) scanf("%d",b+i);
        int best = N;
        for(int S = 4; S--;){
            int x = S&1, y = S>>1;
            b[0] ^= x; b[1] ^= x;
            b[N-2] ^= y; b[N-1] ^= y;
            int v[N+3] = {};
            int rv = 0, ans = x+y;
            for(int i = 0; i < N; i++){
                if(b[i]^(rv^=v[i])){
                    if(i < N-2){
                        v[i+3] ^= 1; rv ^= 1;
                        ans++;
                    }
                    else{
                        ans = best+1; break;
                    }
                }
            }
            best = min(best,ans);
            b[0] ^= x; b[1] ^= x;
            b[N-2] ^= y; b[N-1] ^= y;
        }
        printf("%d
    ", best);
        return 0;
    }
  • 相关阅读:
    线程间的通信
    不用加减乘除做加法
    关键字throw(something)限制
    C++ 中的“ !” 运算
    n个骰子的点数
    State 模式
    Strategy 模式
    构造函数为什么不能是虚函数 ( 转载自C/C++程序员之家)
    n个骰子的点数
    和为S的两个数字
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4975671.html
Copyright © 2011-2022 走看看