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

  1. 4
  2. 1 2 3 3
  3. 4
  4. 1 2 3 4

Sample Output

  1. No
  2. Yes
  3. 1 -1 -1 1
  1. 一组数据,选择其中的一半的数变成负数,加上另一半可以和为0
    输出NO的情况,如果这个数组的和是一个奇数的话,或者只有一个数时,就输出No
    否则输出Yes,先从大到小排序,从最大的开始加和,加到和大于所有数数和一半的就不能加了,或如果这时刚好和等于所有数和的一半,那么你选择的那个数乘-1
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdio>
  4. using namespace std;
  5. long long sum;
  6. int t;
  7. int f[];
  8. struct node
  9. {
  10. int zg;
  11. int id;
  12. };
  13. node a[];
  14. int cmp(node x,node y)
  15. {
  16. return x.zg>y.zg;
  17. }
  18. int main()
  19. {
  20. while(cin>>t)
  21. {
  22. long long sum=;
  23. for(int i=; i<t; i++)
  24. {
  25. cin>>a[i].zg;
  26. a[i].id=i;
  27. f[i]=-;
  28. sum+=a[i].zg;
  29. }
  30. if(sum%||t==) cout<<"No"<<endl;
  31. else
  32. {
  33. cout<<"Yes"<<endl;
  34. sort(a,a+t,cmp);
  35. int s=;
  36. for(int i=; i<t; i++)
  37. {
  38. if(s+a[i].zg<=sum/)
  39. {
  40. s+=a[i].zg;
  41. f[a[i].id]=;
  42. if(s==sum/)
  43. break;
  44. }
  45. }
  46. cout<<f[];
  47. for(int i=; i<t; i++)
  48. {
  49. cout<<' '<<f[i];
  50. }
  51. cout<<endl;
  52. }
  53. }
  54. return ;
  55. }

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. SQL 第二章 作业

    /*第二章 作业*/ create table S ( sno char(2) NOT NULL UNIQUE, sname char(3), city char(2) ); alter table ...

  2. HAProxy、Nginx 配置 HTTP/2 完整指南

    基于最近对HTTP/2的争论和它的优势,是时候升级底层架构了.这篇文章将会介绍如何在安装和配置HAProxy和Ngnix(使用ssl终端).为了简化流程,我建议你准备好使用Docker镜像. 如果你想 ...

  3. Lucene 4.10.2开发示例

    这里面用的是比较新的Lucene4.10.2 做的一个实例.(lucene的索引不能太大,要不然效率会很低.大于1G的时候就必须考虑分布索引的问题) 先介绍一下Lucene的几个参数意义: Index ...

  4. 在线程中进行读取并写入文件和wenjia

    新人求(胸)罩!!! import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException ...

  5. Effect of Switchovers, Failovers, and Control File Creation on Backups

    对dataguard 官方文档里面的这句话不理解,是否能给出一个样例说明: 10.2.0.5的版本号 Effect of Switchovers, Failovers, and Control Fil ...

  6. DateGridew导出Excel表+常见错误提示

    在敲机房收费系统的时候,显示数据的时候需要将DateGridew 中的数据导出进Excel表.DateGridew导出Excel表是比较常见的,当然导出Excel表有很多种方法,下面是个人认为比较容易 ...

  7. [PWA] 3. Devtool

    You can debug with chrom dev tool: 1. Use console to debug service worker: Swith to sw.js context th ...

  8. [CSS3] CSS :target Selector

    The :target selector allows us to interact with a fragment identifier, or hash, in our URL from CSS. ...

  9. IO流--转载

    第 1 部分 从输出流中读取 http://www.ibm.com/developerworks/cn/java/j-io1/ 自早期基于浏览器的 applet 和简单应用程序以来,Java 平台已有 ...

  10. 第二篇:R语言数据可视化之数据塑形技术

    前言 绘制统计图形时,半数以上的时间会花在调用绘图命令之前的数据塑型操作上.因为在把数据送进绘图函数前,还得将数据框转换为适当格式才行. 本文将给出使用R语言进行数据塑型的一些基本的技巧,更多技术细节 ...