ZOJ 2856 Happy Life 暴力求解
因为是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 暴力求解的更多相关文章
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- 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 ...
- hdu6570Wave (暴力求解)
Problem Description Avin is studying series. A series is called "wave" if the following co ...
- <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?
str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n) , 暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...
- HDU 4462 Scaring the Birds (暴力求解,二进制法)
题意:给定一个 n*n的矩阵,在一些位置放上稻草人,每个稻草人的范围是一定,问你最少几个能覆盖整个矩阵. 析:稻草人最多才10个,所以考虑暴力,然后利用二进制法,很容易求解,并且时间很少0ms,注意有 ...
- (暴力求解)Encoding HDU1020
Encoding 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2601An easy problem-素数的运用,暴力求解
id=17433" target="_blank" style="color:blue; text-decoration:none">An ea ...
随机推荐
- @Transactional失效的问题
spring事物配置一般没有问题, 优先检查mysql的引擎是否是innodb, 是的话检查包的扫描是否有问题. 我就是因为包的扫描导致@Transactional失效. 具体情况如下, 在sprin ...
- ssh无密登录
ssh登录一般两种方式: 1.密码登录 2.密钥验证无需密码 使用方式:1.生成密钥 2.将公钥追加到authorized_keys中,需要注意的是执行权限需为600,这里因而第一次添加使用的是> ...
- java中文乱码问题
•ASCII ØASCII使用7个比特(bit)进行字符编码,最多可以表示的字符数量为27(128)个字符,这些字符包括了大小写英文字母.阿拉伯数字.标点符号.控制字符和其他符号.每个字符用一个字节表 ...
- 无法启动此程序,因为计算机中丢失QtCore4.dll。尝试重新安装该程序以解决此问题(在系统里添加3个路径)
解决方法: 计算机-属性-高级系统设置-高级-环境变量-系统变量-Path 添加 E:\Qt\4.8.5\bin; E:\Qt\4.8.5\qmake; E:\mingw\bin 重启计算机 http ...
- Spring Boot使用Druid和监控配置
Spring Boot默认的数据源是:org.apache.tomcat.jdbc.pool.DataSource 整体步骤: (1) -- Druid简单介绍,具体看官网: (2) ...
- 《UNIX环境高级编程》笔记--UNIX标准化及实现
1.UNIX标准化 1.1.ISO C 1989 年后期,C程序设计语言的ANSI(American National Standards Institute) 标准X3. 15 9-1989得到批准 ...
- CCPC L(水)
Huatuo's Medicine Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- MySQl 存储过程+游标
DROP PROCEDURE IF exists pro_Insertflightplan_stat; create procedure pro_Insertflightplan_stat(exec ...
- Spring data redis的一个bug
起因 前两天上线了一个新功能,导致线上业务的缓存总是无法更新,报错也是非常奇怪,redis.clients.jedis.exceptions.JedisConnectionException: Unk ...
- python编写工具及配置(notepad++)
学长跟我说老师实验室里用的ide是pycharm,我用了一天,整体还行,就是加载速度太慢,可是第二天用的时候就卡的想让人骂街,cpu占有率趋近100%,电脑配置不高,我寻思不能因为这个就马上换电脑吧, ...