因为是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. sqlserver 只有函数和扩展存储过程才能从函数内部执行

    一个SQLServer的自定义函数中调用一个自定义的存储过程,执行此函数后发出如下提示:“只有函数和扩展存储过程才能从函数内部执行". 原因:函数只能使用简单的sql语句,逻辑控制语句,复杂 ...

  2. A Byte of Python 笔记(9) 面向对象编程

    第11章  面向对象编程 面向过程:根据操作数据的函数或语句块来设计程序. 面向对象(OOP, object-oriented programming):把数据和功能结合起来,用对象包裹组织程序. 类 ...

  3. Firefox 备份

    参考http://mozilla.com.cn/post/32327/ 火狐的地址栏中输入about:support点击“打开所在文件夹”按钮,会弹出一个资源管理器,并且定位到你当前的Profile文 ...

  4. 深入剖析哪些服务是Oracle 11g必须开启的

    这篇文章主要介绍了哪些服务是Oracle 11g必须开启的以及这些服务的详细介绍,需要的朋友可以参考下   成功安装Oracle 11g数据库后,你会发现自己电脑运行速度会变慢,配置较低的电脑甚至出现 ...

  5. C#使用WinAPI 修改电源设置,临时禁止笔记本合上盖子时睡眠

    原文 http://www.cnblogs.com/h46incon/archive/2013/09/03/3299138.html 在 阻止系统自动睡眠的小软件,附C#制作过程 ,弄了一个防止系统睡 ...

  6. AssetManager中的路径参数不能包含"assets/"

    String path = “music/bg.mp3”: //正确的参数 //String path = “assets/music/bg.mp3”: //错误的参数 //String path = ...

  7. linux-0.11抠代码-GDB+VMWARE

    vmware新建一个虚拟机,硬盘为0.1G,建立完成后要先启动一次虚拟机,此时无任何系统,然后再关闭,应该会多出一个ostest-flat.vmdk这个虚拟磁盘文件,下面要用到 新建完成后 我的虚拟机 ...

  8. Php 使用 fsockopen发送http请求

    <?php function HTTP_Post($URL,$data, $referrer="") { // parsing the given URL $URL_Info ...

  9. jQuery 自学笔记—3

    jQuery 语法实例 $(this).hide() 演示 jQuery hide() 函数,隐藏当前的 HTML 元素. $("#test").hide() 演示 jQuery ...

  10. JAVA中List、Map、Set的区别与选用

    类层次关系如下: Collection ├List│├LinkedList│├ArrayList│└Vector│ └Stack└SetMap├Hashtable├HashMap └WeakHashM ...