ZOJ 2856 Happy Life Violence Solution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.