• ZOJ 2856 Happy Life 暴力求解


    因为是Special Judge 的题目,只要输出正确答案即可,不唯一

    暴力力求解, 只要每次改变 happiness 值为负的人的符号即可。

    如果计算出当前人的 happiness 值为负,那么将其 p(i) 值赋值为-p(i) 即可
    这题是保证有解的,至至于为何难以证明。

    Source Code:

    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <string>
    #include <map>
    #include <set>
    #include <list>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #define Max(a,b) (((a) > (b)) ? (a) : (b))
    #define Min(a,b) (((a) < (b)) ? (a) : (b))
    #define Abs(x) (((x) > 0) ? (x) : (-(x)))
    #define MOD 1000000007
    #define pi acos(-1.0)
    
    using namespace std;
    
    typedef long long           ll      ;
    typedef unsigned long long  ull     ;
    typedef unsigned int        uint    ;
    typedef unsigned char       uchar   ;
    
    template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
    template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;}
    
    const double eps = 1e-7      ;
    const int N = 210            ;
    const int M = 1100011*2      ;
    const ll P = 10000000097ll   ;
    const int MAXN = 10900000    ;
    
    int a[220][220], n;
    int ans[220];
    
    int main(){
        std::ios::sync_with_stdio(false);
        int i, j, t, k, u, v, numCase = 0;
    
        while (EOF != scanf ("%d",&n)) {
            for (i = 1; i <= n; ++i) {
                for (j = 1; j <= n; ++j) {
                    scanf("%d", &a[i][j]);
                }
            }
            for (i = 1; i <= n; ++i)    ans[i] = 1;
            int cnt = 1;
            for (;;) {
                if (cnt > n)   break;
                int sum = 0;
                for (i = 1; i <= n; ++i) {
                    sum += a[cnt][i] * ans[i];
                }
                if (sum * ans[cnt] < 0) {
                    ans[cnt] = -ans[cnt];
                    cnt = 1;
                } else {
                    ++cnt;
                }
            }
            printf ("Yes
    ");
            for (i = 1; i <= n; ++i) {
                if (ans[i] == 1) {
                    printf("+
    ");
                } else {
                    printf("-
    ");
                }
            }
        }
    
        return 0;
    }
  • 相关阅读:
    Jenkins 的安装部署
    Python /usr/bin/python
    java学习基础 项目
    Java 并行与并发
    c# 将一个窗体显示在主窗体中
    java.io.IOException: open failed: EACCES (Permission denied) 问题解决
    android中创建模拟器的 SDCard
    Android学习笔记__2__Android工程目录结构
    Android学习笔记__3__Android应用程序组成
    Android学习笔记__1__Android体系架构
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4375760.html
Copyright © 2020-2023  润新知