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

4
1 2 3 3
4
1 2 3 4

Sample Output

No
Yes
1 -1 -1 1

Source



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

[Submit]  [Go Back]  [Status]

排序之后贪心瞎搞。。。

/*************************************************************************
> File Name: c.cpp
> Author: acvcla
> QQ:
> Mail: acvcla@gmail.com
> Created Time: 2014年10月11日 星期六 08时42分28秒
************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
int A[maxn],cnt[maxn],f[maxn];
std::vector<int> v;
int main(){
int n;
while(~scanf("%d",&n)&&n){
memset(cnt,0,sizeof(cnt));
memset(f,0,sizeof f);
v.clear();
LL sum=0;
LL M=0;
for(int i=1;i<=n;i++){
scanf("%d",A+i);
if(A[i]>M)M=A[i];
sum+=A[i];
cnt[A[i]]++;
}
if(sum&1){
puts("No");
continue;
}
sum/=2;
bool ok=false;
for(int i=M;!ok&&i>=1;i--){
f[i]=min((LL)cnt[i],sum/i);
sum-=(LL)f[i]*i;
if(sum==0){
ok=true;
break;
}
}
if(!ok){
puts("No");
}else{
puts("Yes");
for(int i=1;i<=n;i++){
if(i==1){
if(f[A[i]]>0){
printf("1");
f[A[i]]--;
}
else printf("-1");
}
else{
if(f[A[i]]>0){
printf(" 1");
f[A[i]]--;
}
else printf(" -1");
}
}
puts("");
} }
return 0;
}

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. [ARC055D]隠された等差数列

    题意:对一个等差数列$a_i=A+Bi(0\leq i\leq n-1)$和非负整数$x$,把$a_i$的$10^x$位拿出来可以写成一个字符集为$0\cdots9$的字符串,现在给定这个字符串$d_ ...

  2. 理解HashSet及使用

    (1) 为啥要用HahSet?    假如我们现在想要在一大堆数据中查找X数据.LinkedList的数据结构就不说了,查找效率低的可怕.ArrayList哪,如果我们不知道X的位置序号,还是一样要全 ...

  3. centos 7 修改ssh登录端口

    在阿里云上面使用的oneinstack镜像,默认是使用的22端口,每次登录总会发现有人在暴力破解我的服务器,所以想想还是修改一下比较安全. 1.在防火墙打开新的端口 iptables -I INPUT ...

  4. bzoj 2770 堆的中序遍历性质

    我们知道二叉搜索树的中序遍历是一个已经排好序的序列,知道序列我们无法确定树的形态(因为有多种). 但是,Treap如果告诉我们它的关键字以及权值,那么就可以唯一确定树的形态(Treap的O(logn) ...

  5. 二、python的逻辑运算与数据类型

    .python的逻辑运算符 数学运算符 加:+   减:-  乘:*  除:/  取余:% 关系运算符 等于: ==  不等于: != 小于:< 大于:>     大于等于: >=  ...

  6. Apache -- 利用.htaccess防盗链

    在Apache服务器的前提下利用.htaccess文件来防盗链的原理是通过检查图片或文件请求头信息中的Referer属性(也就是请求的来源),判断它是否属于你所规定的合法的请求来源,从而实现让合法来源 ...

  7. ACM -- 算法小结(七)Phone list解题报告

          HDOJ -- Phone list解题报告 问题描述:给出一些电话号码,如果有共同前缀则输出NO,如果没有则输出YES. 解题关键:将电话号码进行字符串排序,相邻的电话号码进行比较 Sa ...

  8. 思科DCHP解决方案

    DHCP功能平时用的不算少,而且本人的几乎所有的DHCP功能都是在交换机上实现的,虽然也可以通过PC实现,而且PC的DHCP Server功能还更完善,比如可以不受DHCP作用域的限制.IP分配情况直 ...

  9. 了解你的Linux系统:必须掌握的20个命令

    转载:http://blog.chinaunix.net/uid-16459552-id-3877787.html 要想详细了解你的Linux系统,为系统评估和性能调化提供准确的信息,那么,你会经常用 ...

  10. web.xml加载顺序 [转载]

    一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...