UVA - 1614 Hell on the Market(贪心)
 Description  
Most financial institutions had become insolvent during financial crisis and went bankrupt or were bought by larger institutions, usually by banks. By the end of financial crisis of all the financial institutions only two banks still continue to operate. Financial markets had remained closed throughout the crisis and now regulators are gradually opening them. To prevent speculation and to gradually ramp up trading they will initially allow trading in only one financial instrument and the volume of trading will be limited to i<tex2html_verbatim_mark> contracts for i<tex2html_verbatim_mark> -th minute of market operation. Two banks had decided to cooperate with the government to kick-start the market operation. The boards of directors had agreed on trading volume for each minute of this first trading session. One bank will be buying ai<tex2html_verbatim_mark> contracts ( 1 InputThe input file contains several test cases, each of them as described below. The first line of the input contains the single integer number n<tex2html_verbatim_mark> ( 1 OutputFor each test case, the first line of the output must contain `` Yes'' if the trading session with specified volumes is possible and `` No'' otherwise. In the former option a second line must contain n<tex2html_verbatim_mark> numbers -- bi<tex2html_verbatim_mark> . Sample Input4 Sample OutputNo 一组数据,选择其中的一半的数变成负数,加上另一半可以和为0  | 
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long sum;
int t;
int f[];
struct node
{
int zg;
int id;
};
node a[];
int cmp(node x,node y)
{
return x.zg>y.zg;
}
int main()
{
while(cin>>t)
{
long long sum=;
for(int i=; i<t; i++)
{
cin>>a[i].zg;
a[i].id=i;
f[i]=-;
sum+=a[i].zg;
}
if(sum%||t==) cout<<"No"<<endl;
else
{
cout<<"Yes"<<endl;
sort(a,a+t,cmp);
int s=;
for(int i=; i<t; i++)
{
if(s+a[i].zg<=sum/)
{
s+=a[i].zg;
f[a[i].id]=;
if(s==sum/)
break;
}
}
cout<<f[];
for(int i=; i<t; i++)
{
cout<<' '<<f[i];
}
cout<<endl;
}
}
return ;
}
UVA - 1614 Hell on the Market(贪心)的更多相关文章
- UVa 1614 Hell on the Markets (贪心+推理)
		
题意:给定一个长度为 n 的序列,满足 1 <= ai <= i,要求确实每一个的符号,使得它们和为0. 析:首先这一个贪心的题目,再首先不是我想出来的,是我猜的,但并不知道为什么,然后在 ...
 - uva 1614奇怪的股市(归纳法证明,贪心)
		
uva 1614奇怪的股市(归纳法证明,贪心) 输入一个长度为n的序列a,满足\(1\le a_i\le i\),要求确定每个数的正负号,使得所有数的总和为0.例如a={1, 2, 3, 4},则4个 ...
 - Uva 11729  Commando War (简单贪心)
		
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
 - uva 1153 顾客是上帝(贪心)
		
uva 1153 顾客是上帝(贪心) 有n个工作,已知每个工作需要的时间q[i]和截止时间d[i](必须在此前完成),最多能完成多少个工作?工作只能串行完成,第一项任务开始的时间不早于时刻0. 这道题 ...
 - UVA 1614  - Hell on the Markets 奇怪的股市(贪心,结论)
		
先证明一个结论吧,对于1≤ai≤i+1,前面ai个数一定可以凑出1~sum[i]中的任意一个数. 对于i=1显然成立, 假设对于i=k结论成立,那么对于i=k+1来说,只要证明sum[k]+i,1≤i ...
 - 【uva 1614】Hell on the Markets(算法效率--贪心)
		
题意:有一个长度为N的序列A,满足1≤Ai≤i,每个数的正负号不知.请输出一种正负号的情况,使得所有数的和为0.(N≤100000) 解法:(我本来只想静静地继续做一个口胡选手...←_← 但是因为这 ...
 - 紫书 习题8-10 UVa 1614 (贪心+结论)
		
这道题我苦思冥想了一个小时, 想用背包来揍sum/2, 然后发现数据太大, 空间存不下. 然后我最后还是去看了别人的博客, 发现竟然有个神奇的结论-- 幸好我没再钻研, 感觉这个结论我肯定是想不到的- ...
 - UVA - 1614 Hell on the Markets(奇怪的股市)(贪心)
		
题意:输入一个长度为n(n<=100000)的序列a,满足1<=ai<=i,要求确定每个数的正负号,使得所有数的总和为0. 分析: 1.若总和为0,则未加符号之前,所有数之和必为偶数 ...
 - UVA 538 - Balancing Bank Accounts(贪心)
		
UVA 538 - Balancing Bank Accounts 题目链接 题意:给定一些人的欠钱关系,要求在n-1次内还清钱,问方案 思路:贪心,处理出每一个人最后钱的状态,然后直接每一个人都和最 ...
 
随机推荐
- 浅谈二维RMQ
			
针对一些二维区间最值问题,用一维RMQ来解决显然是不够的.所以,要改进算法.鉴于网上没有PASCAL版的RMQ标程与解析,所以小可在这里简单的讲一下. 核心思想和一维的一样,只是在计算区间时略有不同. ...
 - 《程序设计中的组合数学》——polya计数
			
我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...
 - 性能比较工具runstats
			
runstats能对做同一件事的两个不同方法进行比较,得出谁好一点.我们只需要提供两个不同方法,余下的事情都由runstats负责.runstats只是测量3个要素: 1. 耗用的时间. 2. 系统统 ...
 - C#构造函数里的base和this的区别
			
用法一: 父类的构造函数总是在子类之前执行的.既先初始化静态构造函数,后初始化子类构造函数. public class BaseCircle { public BaseCircle() { Conso ...
 - 在安装twincat plc时,出现 there are some files marked for deletion on next reboot.please reboot first then
			
在注冊表内"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\ "中删除注冊表值 " ...
 - Linux下一个Redis启动/关闭/重新启动服务脚本
			
脚本功能: 实现redis单机多实例情况下的正常启动.关闭.重新启动单个redis实例.完毕系统标准服务的下面经常使用功能: start|stop|status|restart 注:redis程序代 ...
 - configure JAAS for jboss 7.1 and mysql--reference
			
Hello all, In this tutorial we are going to configure JAAS for jboss 7.1 and mysql for Form based au ...
 - ajax提交富文本,内容被截断,解决方法及思路
			
问题描述: 使用百度的UEditor富文本插件用于前端富文本编辑,后端使用jsp,提交普通文本没有问题,后来发现在提交某些指定文本时,数据查回的数据出现不完整现象:第一件事就是想到“垃圾编辑器”
 - jsp引入struts标签,引入自己写的jquery需要注意的问题
			
1.使用struts2标签的时候在jsp页面开头引入这句话: <%@ taglib prefix="s" uri="/struts-tags"%> ...
 - Datables wrning(table id='example'):Cannot reinitialise DataTable.
			
出现的问题如下所示: Datables wrning(table id='example' Datables object for this table,please pass eithser no ...