Because it is special Judge problem, as long as the correct answer can be output, not the only
Violence seeks to solve, as long as each change happiness value is negative of the person's symbol.
If the current person's happiness value is calculated as negative, then the P (i) value is assigned to-P (i)
This question is guaranteed to be solvable, and it is difficult to prove why.
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>#defineMax (b) ((a) > (b))? (a): (b))#defineMin (b) ((a) < (a))? (a): (b))#defineAbs (x) (((x) > 0)? (x): (-(x)))#defineMOD 1000000007#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll; typedef unsignedLong Longull; typedef unsignedint UINT; typedef unsignedCharUchar; template<classT> InlinevoidCheckmin (T &a,t b) {if(a>b) a=b;} Template<classT> InlinevoidCheckmax (T &a,t b) {if(a<b) a=b;}Const DoubleEPS = 1e-7 ;Const intN = About ;Const intM =1100011*2 ;Constll P =10000000097ll;Const intMAXN =10900000 ;inta[ -][ -], N;intans[ -];intMain () {Std::ios::sync_with_stdio (false); intI, 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; intCNT =1; for (;;) { if(CNT > N) Break; intsum =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;}
ZOJ 2856 Happy Life Violence Solution