Problem Description

Do you know Utopia? It's a perfect world in which everyone leads a happy life.

A fairy wants to make a naive Utopia City. She studies the factors that have an impact on people's happiness and thinks that a person is happy if and only if all other persons' total "influence factor" on him (or her) is nonnegative. Each person has an influence factor on another person, which may be a positive integer or negative integer or 0. The influence factor is always symmetric, that is, if person A has an influence factor f on person B, it means that person B also has an "influence factor" f on A. So we can say the influence factor between person A and B is f without confusion. A person's influence factor on himself (or herself) is always 0. So let f(i, j) be the influence factor between person i and person j and person i's happiness(i) is well defined as follows:

Obviously there may be some persons who are not happy. Though the fairy cannot change any influence factor, she can give every person a property p(i) which is always +1 or -1. Under the fairy's magical definition, a person i's happiness(i)' is redefined as follow:

Person i feels happy if the value of happiness(i)' is nonnegative. But the fairy wonders whether she can give everyone a property to make all of them happy so that she can build her ideal naive Utopia successfully.

Since you're an ace programmer, the fairy asks you to help her to fulfill her dream. Can you help her?

Input

The input contains multiple test cases!

Each test case starts with an integer N (2 <= N <= 200), the number of persons in the city. After that there're N lines of integers and each line consists of N integers. The j-th integer of the i-th line of the matrix indicates the influence factor f(i,j) (-1000 < f(i,j) < 1000).

Proceed to the End Of File (EOF).

Output

For each test case, if the fairy fails, output a single line with "No" (without the quotations), otherwise output "Yes" (without the quotations) in the first line, followed by N lines, each line contains exactly a "+" (without the quotations) or a "-"(without the quotations) to indicate that the fairy should give the i-th person property +1 or -1 to fulfill her dream.

Sample Input

3
0 1 3
1 0 -1
3 -1 0
2
0 -10
-10 0

Sample Output

Yes
-
+
-
Yes
+
-

暴力,为什么不会出现No的情况呢?

#include <stdio.h>
#define MAXN 220 int n;
int g[MAXN][MAXN];
int ans[MAXN]; int main(){
int i,j;
while( scanf("%d",&n)!=EOF ){
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
scanf("%d" ,&g[i][j]);
}
ans[i]=1;
}
int index=1;
while(1){
if(index==n+1){
break;
}
int sum=0;
for(i=1; i<=n; i++){
sum+=ans[i]*g[index][i];
}
if(sum*ans[index]<0){
ans[index]*=-1;
index=1;
}
else index++;
}
puts("Yes");
for(int i=1; i<=n; i++){
if(ans[i]<0)
puts("-");
else
puts("+");
}
}
return 0;
}

ZOJ 2856 Happy Life的更多相关文章

  1. ZOJ 2856 Happy Life 暴力求解

    因为是Special Judge 的题目,只要输出正确答案即可,不唯一 暴力力求解, 只要每次改变 happiness 值为负的人的符号即可. 如果计算出当前人的 happiness 值为负,那么将其 ...

  2. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  3. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  4. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  5. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  6. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  7. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  8. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  9. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

随机推荐

  1. vue环境中生成二维码

    <template><div><div id='code'></div><canvas id="canvas">< ...

  2. Android-监听操作系统短信

    想要访问Android操作系统的ContentProvider就需要明白以下原理: 在Android操作系统里面的 /packsges/目录: apps: 很多的系统应用,例如:联系人,浏览器,音乐播 ...

  3. Android-获取网络图片设置壁纸

    下载图片,设置壁纸 的代码: package liudeli.async; import android.app.Activity; import android.app.ProgressDialog ...

  4. JAVA IO总结及socket简单实现

    为了方便理解与阐述,先引入两张图: a.Java IO中常用的类 在整个Java.io包中最重要的就是5个类和一个接口.5个类指的是File.OutputStream.InputStream.Writ ...

  5. 直接导入用户信息到discuz ucenter.

    上一篇帖子: 直接导入帖子到Discuz 论坛数据库. 结束时说要写一篇导入用户的帖子, 一直没时间, 但是咱不能做太监,不是? 所以今天赶快补上. 在做discuz整合或者迁移是, 很多人可能遇到相 ...

  6. 洛谷P3613 睡觉困难综合征

    传送门 题解 人生第一道由乃…… 做这题之前应该先去把这一题给切掉->这里 我的题解->这里 然后先膜一波zsy大佬和flashhu大佬 大体思路就是先吧全0和全1的都跑答案,然后按位贪心 ...

  7. [ActionScript 3.0] AS利用ByteArray向PHP发送二进制数据生成图片

    flash as3向php发送二进制数据,通过php保存成图片. AS端: package { import com.JPEGEncoder.JPGEncoder; import flash.disp ...

  8. java执行命令行命令

    package javai; import java.io.BufferedReader; import java.io.InputStreamReader; public class IOTest ...

  9. selenium上传图片

    在我们使用selenium的时候碰到上传图片.文件时一般都可以先定位然后直接send_keys,但是有的却不行,selenium也没有提供其它的办法,只能靠第三方软件来解决 我们要借助一个叫AutoI ...

  10. CH2601 电路维修(双端队列bfs)建图恶心

    CH2601 电路维修 双端队列bfs,其实就是因为只有0和1所以可以直接2维护队列单调性(和优先队列一个道理) 建图的过程需要仔细斟酌(想一想id为什么这么写) 还有,空间要开够(很玄学),我一开始 ...