Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

Submit Status

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 ( 1aii<tex2html_verbatim_mark> ) during i<tex2html_verbatim_mark> -th minute ( 1in<tex2html_verbatim_mark> ), while the other one will be selling. They do not really care whether to buy or to sell, and the outside observer will only see the volume ai<tex2html_verbatim_mark> of contracts traded per minute. However, they do not want to take any extra risk and want to have no position in the contract by the end of the trading session. Thus, if we define bi = 1<tex2html_verbatim_mark> when the first bank is buying and bi = - 1<tex2html_verbatim_mark>when the second one is buying (and the first one is selling), then the requirement for the trading session is that aibi = 0<tex2html_verbatim_mark> . Your lucky team of three still works in the data center (due to the crisis, banks now share the data center and its personnel) and your task is to find such bi<tex2html_verbatim_mark> or to report that this is impossible.

Input

The 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> ( 1n100 000<tex2html_verbatim_mark> ). The second line of the input contains n<tex2html_verbatim_mark> integer numbers -- ai<tex2html_verbatim_mark> ( 1aii<tex2html_verbatim_mark> ).

Output

For 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 Input

4
1 2 3 3
4
1 2 3 4

Sample Output

No
Yes
1 -1 -1 1
一组数据,选择其中的一半的数变成负数,加上另一半可以和为0
输出NO的情况,如果这个数组的和是一个奇数的话,或者只有一个数时,就输出No。
否则输出Yes,先从大到小排序,从最大的开始加和,加到和大于所有数数和一半的就不能加了,或如果这时刚好和等于所有数和的一半,那么你选择的那个数乘-1。
#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(贪心)的更多相关文章

  1. UVa 1614 Hell on the Markets (贪心+推理)

    题意:给定一个长度为 n 的序列,满足 1 <= ai <= i,要求确实每一个的符号,使得它们和为0. 析:首先这一个贪心的题目,再首先不是我想出来的,是我猜的,但并不知道为什么,然后在 ...

  2. uva 1614奇怪的股市(归纳法证明,贪心)

    uva 1614奇怪的股市(归纳法证明,贪心) 输入一个长度为n的序列a,满足\(1\le a_i\le i\),要求确定每个数的正负号,使得所有数的总和为0.例如a={1, 2, 3, 4},则4个 ...

  3. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  4. uva 1153 顾客是上帝(贪心)

    uva 1153 顾客是上帝(贪心) 有n个工作,已知每个工作需要的时间q[i]和截止时间d[i](必须在此前完成),最多能完成多少个工作?工作只能串行完成,第一项任务开始的时间不早于时刻0. 这道题 ...

  5. 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 ...

  6. 【uva 1614】Hell on the Markets(算法效率--贪心)

    题意:有一个长度为N的序列A,满足1≤Ai≤i,每个数的正负号不知.请输出一种正负号的情况,使得所有数的和为0.(N≤100000) 解法:(我本来只想静静地继续做一个口胡选手...←_← 但是因为这 ...

  7. 紫书 习题8-10 UVa 1614 (贪心+结论)

    这道题我苦思冥想了一个小时, 想用背包来揍sum/2, 然后发现数据太大, 空间存不下. 然后我最后还是去看了别人的博客, 发现竟然有个神奇的结论-- 幸好我没再钻研, 感觉这个结论我肯定是想不到的- ...

  8. UVA - 1614 Hell on the Markets(奇怪的股市)(贪心)

    题意:输入一个长度为n(n<=100000)的序列a,满足1<=ai<=i,要求确定每个数的正负号,使得所有数的总和为0. 分析: 1.若总和为0,则未加符号之前,所有数之和必为偶数 ...

  9. UVA 538 - Balancing Bank Accounts(贪心)

    UVA 538 - Balancing Bank Accounts 题目链接 题意:给定一些人的欠钱关系,要求在n-1次内还清钱,问方案 思路:贪心,处理出每一个人最后钱的状态,然后直接每一个人都和最 ...

随机推荐

  1. nyist 58 最小步数 BFS

    最少步数 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 这有一个迷宫,有0~8行和0~8列: 1,1,1,1,1,1,1,1,1 1,0,0,1,0,0,1,0,1 1,0 ...

  2. 用Processon在线绘制UML的尝试

    地址https://www.processon.com/ ProcessOn是一个面向垂直专业领域的作图工具和社交网络,成立于2011年6月并于2012年启动.ProcessOn将全球的专家顾问.咨询 ...

  3. CentOS-6.4-i386硬盘安装

    由于安装程序不能识别NTFS分区上的镜像,因此需要变通,网上可参考的文章分为两种方法: 1.使用分区工具创建EXT分区,再用Windows下可访问EXT分区的软件,将安装镜像拷入进行安装. 2.使用分 ...

  4. pygame学习资料

    pygame下载地址: https://bitbucket.org/pygame/pygame/downloads 12岁的少年教你用Python做小游戏 Beginning Game Program ...

  5. 【转载】运维小技巧:使用ss命令代替 netstat

    转自:https://www.91ri.org/12470.html ss是Socket Statistics的缩写. 顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类 ...

  6. input页面居中,软键盘覆盖input

    input框位于底部 对于ios的软键盘遮盖input输入框问题,网上已经有了一些解决办法,无非就是改变布局,再加scroll.js插件实现滚动, input框位于顶部 这种情况不会出现问题, inp ...

  7. 对于数组(字符串)slice方法的总结

    数组(字符串)使用slice方法的目的就是截取目标数组(字符串),通俗的来讲就是截取想要的.网上有很多slice方法的实例加以说明,在此主要是从特殊到一般对此方法进行了总结. 先说总结的方法,再看下面 ...

  8. 小学生玩ACM----深搜

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  9. Team Foundation Server 2013 with Update 3 Install LOG

    [Info   @10:14:58.155] ====================================================================[Info   @ ...

  10. [TypeScript] Inheritance

    Inheritance is a way toindicate that a class receives behavior from a parent class. Then we can over ...