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

[Submit]  [Go Back]  [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 contracts for i -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 contracts ( 1aii
) during i -th minute ( 1in
), 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 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 when the first bank is buying and
bi = - 1 when the second one is buying (and the first one is selling), then the requirement for the trading session is that
aibi = 0 . 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 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 ( 1n100 000
). The second line of the input contains n integer numbers --
ai ( 1aii
).

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 numbers -- bi .

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

Source



Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 8. Algorithm Design ::
Exercises

[Submit]  [Go Back]  [Status]

排序之后贪心瞎搞。。。

  1. /*************************************************************************
  2. > File Name: c.cpp
  3. > Author: acvcla
  4. > QQ:
  5. > Mail: acvcla@gmail.com
  6. > Created Time: 2014年10月11日 星期六 08时42分28秒
  7. ************************************************************************/
  8. #include<iostream>
  9. #include<algorithm>
  10. #include<cstdio>
  11. #include<vector>
  12. #include<cstring>
  13. #include<map>
  14. #include<queue>
  15. #include<stack>
  16. #include<string>
  17. #include<cstdlib>
  18. #include<ctime>
  19. #include<set>
  20. #include<math.h>
  21. using namespace std;
  22. typedef long long LL;
  23. const int maxn = 1e5 + 10;
  24. #define rep(i,a,b) for(int i=(a);i<=(b);i++)
  25. #define pb push_back
  26. int A[maxn],cnt[maxn],f[maxn];
  27. std::vector<int> v;
  28. int main(){
  29. int n;
  30. while(~scanf("%d",&n)&&n){
  31. memset(cnt,0,sizeof(cnt));
  32. memset(f,0,sizeof f);
  33. v.clear();
  34. LL sum=0;
  35. LL M=0;
  36. for(int i=1;i<=n;i++){
  37. scanf("%d",A+i);
  38. if(A[i]>M)M=A[i];
  39. sum+=A[i];
  40. cnt[A[i]]++;
  41. }
  42. if(sum&1){
  43. puts("No");
  44. continue;
  45. }
  46. sum/=2;
  47. bool ok=false;
  48. for(int i=M;!ok&&i>=1;i--){
  49. f[i]=min((LL)cnt[i],sum/i);
  50. sum-=(LL)f[i]*i;
  51. if(sum==0){
  52. ok=true;
  53. break;
  54. }
  55. }
  56. if(!ok){
  57. puts("No");
  58. }else{
  59. puts("Yes");
  60. for(int i=1;i<=n;i++){
  61. if(i==1){
  62. if(f[A[i]]>0){
  63. printf("1");
  64. f[A[i]]--;
  65. }
  66. else printf("-1");
  67. }
  68. else{
  69. if(f[A[i]]>0){
  70. printf(" 1");
  71. f[A[i]]--;
  72. }
  73. else printf(" -1");
  74. }
  75. }
  76. puts("");
  77. }
  78.  
  79. }
  80. return 0;
  81. }

UVA1614(贪心)的更多相关文章

  1. UVA-1614 Hell on the Markets(贪心+推理) (有待补充)

    题目大意:一个整数序列a,1≤a[i]≤i.问能否通过在一些元素前加上负号,使得整个序列和为0. 题目分析:贪心.贪心策略:每次都先选最大的元素加负号(或保留,不加负号). 贪心依据:对于1≤a[i] ...

  2. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  3. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  8. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  9. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

随机推荐

  1. Vue组件深入了解(组件注册和Prop)

    一.组件名 自定义组件的名称强烈推荐遵循W3C规范中的方式:字母全小写且必须包含一个连字符. 二.全局注册和局部注册的区别 全局注册 Vue.component进行注册.全局注册的可以在任何创建的实例 ...

  2. C++ -- STL泛型编程(二)之set

    set集合容器实现了红黑树的平衡二叉检索树的数据结构,在插入元素时候它会自动调整二叉树的排列,把元素放在适当的位置,以确保每个子树根节点的键值都大于左子树的所有节点的键值,而小于右子树的所有节点的键值 ...

  3. PAT甲级1018. Public Bike Management

    PAT甲级1018. Public Bike Management 题意: 杭州市有公共自行车服务,为世界各地的游客提供了极大的便利.人们可以在任何一个车站租一辆自行车,并将其送回城市的任何其他车站. ...

  4. 慢查询日志分析工具之pt-query-digest

    简介        pt-query-digest 是用于分析mysql慢查询的一个工具,与mysqldumpshow工具相比,py-query_digest 工具的分析结果更具体,更完善. 有时因为 ...

  5. Low-cost ADC using only Digital I/O

    http://letsmakerobots.com/node/13843 Reading A Sensor With Higher Accuracy – RC Timing Method RC Tim ...

  6. TSL / SSL

    参考: http://www.ruanyifeng.com/blog/2014/09/illustration-ssl.html http://www.tuicool.com/articles/IJ3 ...

  7. TortoiseSVN 图文使用教程

      1 安装及下载client 端 2 什么是SVN(Subversion)? 3 为甚么要用SVN? 4 怎么样在Windows下面建立SVN Repository? 5 建立一个Working目录 ...

  8. Selenium2+python自动化70-unittest之跳过用例(skip)

    前言 当测试用例写完后,有些模块有改动时候,会影响到部分用例的执行,这个时候我们希望暂时跳过这些用例. 或者前面某个功能运行失败了,后面的几个用例是依赖于这个功能的用例,如果第一步就失败了,后面的用例 ...

  9. python笔记6-%u60A0和\u60a0类似unicode解码

    前言 有时候从接口的返回值里面获取到的是类似"%u4E0A%u6D77%u60A0%u60A0"这种格式的编码,不是python里面的unicode编码. python里面的uni ...

  10. maven编译错误,警告: BASE64Decoder是内部专用 API, 可能会在未来发行版中删除

    修改红色部分版本号为2.3.2              <plugin>                 <groupId>org.apache.maven.plugins& ...