因为是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\n"); for (i = 1; i <= n; ++i) { if (ans[i] == 1) { printf("+\n"); } else { printf("-\n"); } } } return 0; }
时间: 2024-10-07 05:46:38