天天看点

ZOJ 2856 Happy Life(数论,暴力)

题目链接:http://vj.hsacm.com/problem/visitOriginUrl.action?id=74912

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
int main()
{
    int n;
    while (cin >> n)
    {
        if (n == )
            break;
        int peo[][];
        int happy[];
        for (int i = ; i <= n; ++i)
        {
            for (int j = ; j <= n; ++j)
            {
                cin >> peo[i][j];
                happy[i] = ;
            }
        }
        for (int k = ; k <= n;)
        {
            int sum = ;
            for (int i = ; i <= n; ++i)
                sum += happy[i] * peo[k][i];
            sum *= happy[k];
            if (sum < )
            {
                happy[k] *= -;
                k = ;
                continue;
            }
            k++;
        }
        cout << "Yes" << endl;
        for (int i = ; i <= n; ++i)
            cout << (happy[i] ==  ? "+" : "-") << endl;
    }
    return ;
}
           
zoj