因为是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- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ; int a[][], n;
int ans[]; int main(){
std::ios::sync_with_stdio(false);
int i, j, t, k, u, v, numCase = ; while (EOF != scanf ("%d",&n)) {
for (i = ; i <= n; ++i) {
for (j = ; j <= n; ++j) {
scanf("%d", &a[i][j]);
}
}
for (i = ; i <= n; ++i) ans[i] = ;
int cnt = ;
for (;;) {
if (cnt > n) break;
int sum = ;
for (i = ; i <= n; ++i) {
sum += a[cnt][i] * ans[i];
}
if (sum * ans[cnt] < ) {
ans[cnt] = -ans[cnt];
cnt = ;
} else {
++cnt;
}
}
printf ("Yes\n");
for (i = ; i <= n; ++i) {
if (ans[i] == ) {
printf("+\n");
} else {
printf("-\n");
}
}
} return ;
}

ZOJ 2856 Happy Life 暴力求解的更多相关文章

  1. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  2. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  3. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  4. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  5. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  6. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

  7. HDU 4462 Scaring the Birds (暴力求解,二进制法)

    题意:给定一个 n*n的矩阵,在一些位置放上稻草人,每个稻草人的范围是一定,问你最少几个能覆盖整个矩阵. 析:稻草人最多才10个,所以考虑暴力,然后利用二进制法,很容易求解,并且时间很少0ms,注意有 ...

  8. (暴力求解)Encoding HDU1020

    Encoding 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 Time Limit: 2000/1000 MS (Java/Others)    ...

  9. HDU 2601An easy problem-素数的运用,暴力求解

    id=17433" target="_blank" style="color:blue; text-decoration:none">An ea ...

随机推荐

  1. HTML+CSS笔记 CSS入门

    简介: </span>年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的<span>脚本解释程序</span>,作为ABC语言的一种继承. & ...

  2. Array.Add () and += in PowerShell

    $newArray = @() $newArray.Add("Hello") If I create a new array, and using the method Add() ...

  3. IOS 学习笔记(1) 视图UIViewController

    1.UIViewController *newController=[[UIViewController alloc] initWithNibName:@"XXX" bundle: ...

  4. 静态编译Qt5.4.1和Qt WebKit(网事如风的blog)good

    blog文章地址:http://godebug.org/index.php/archives/133/ WebKit是个好东西,做爬虫.显示网页还是想用HTML来做桌面应用的界面都可以用他,不过一直以 ...

  5. Color the ball(树状数组+线段树+二分)

    Color the ball Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  6. 08.net网站开发(前端):5.jQuery

    开发网站肯定要会JS,嫌代码太难看难学那至少要学会jQuery.当然我见过有些项目纯用服务端控件也是能做出来的,但我相信,那些碰到复杂的需求的话肯定很棘手的.jQuery是对JS和DOM的封装,少量代 ...

  7. hadoop权威指南 chapter1 Meet Hadoop

    Meet Hadoop 1.1 Data!(数据) Most of the data is locked up in the largest web properties (like search e ...

  8. http动态调用webserive

    前言 传统方式调用WebService是直接引用服务,生成客户端代理类类,这种方式将ws进行了再次封装,并以代理的方式进行调用,这种方式的优点是简单,方便. 但是此种方式不足的地方是,当对方ws接口变 ...

  9. ServiceBase 类

    https://msdn.microsoft.com/zh-cn/library/System.ServiceProcess.ServiceBase%28v=vs.80%29.aspx 为将作为服务应 ...

  10. Oracle创建表、索引、主键、字段描述

    -- 创建表 create table SX04_LBALANCE ( YEAR VARCHAR2(10) not null, PROGRAMNO VARCHAR2(40) not null, FDA ...