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. Miller-Rabin算法 codevs 1702 素数判定 2

    转载自:http://www.dxmtb.com/blog/miller-rabbin/ 普通的素数测试我们有O(√ n)的试除算法.事实上,我们有O(slog³n)的算法. 定理一:假如p是质数,且 ...

  2. BZOJ 3571 画框 KM算法 最小乘积最大权匹配

    题意 有n个画框和n幅画.若第i幅画和第j个画框配对,则有平凡度Aij和违和度Bij,一种配对方案的总体不和谐度为∑Aij*∑Bij.求通过搭配能得到的最小不和谐度是多少. n <= 70. 分 ...

  3. 常用 iOS 开源库和第三方组件

    1.通过CocoaPods安装 项目名称 项目信息 AFNetworking 网络请求组件 FMDB 本地数据库组件 SDWebImage 多个缩略图缓存组件 UICKeyChainStore 存放用 ...

  4. CSS的outline属性

    input标签的outline的三个属性: outline-color outline-style outline-width 当设置input的focus状态的时候可以使用. input:focus ...

  5. 关于MORMOT跨平台

    关于MORMOT跨平台 MORMOT服务端程序,支持Win32 / Win64.还有LINUX,通过FPC. 但是你能够写一个客户端在所有DELPHI支持的平台,要使用 cross-platform ...

  6. 解析天气预报JSON数据

    解析天气预报JSON数据 JSON字符串 constjson2 = '{' + #13#10 +'"error":0,' + #13#10 +'"status" ...

  7. telnet用法 测试端口号

    Telnet是进行远程登录的标准协议和主要方式它为用户提供了在本地计算机上完成远程主机工作的能力.可以用telnet命令来测试端口号是否正常打开还是关闭状态. 工具/原料 电脑 cmd命令 方法/步骤 ...

  8. 科普:UTF-8 GBK UTF8 GB2312 之间的区别和关系

    UTF-8:Unicode TransformationFormat-8bit,允许含BOM,但通常不含BOM.是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24为(三 ...

  9. Elasticsearch Groovy任意命令执行漏洞EXP

    测试url:http://190.196.67.252:9200/_search?pretty http://191.234.18.14:9200///_search?pretty POST提交 {“ ...

  10. UVA 10123 No Tipping (物理+贪心+DFS剪枝)

    Problem A - No Tipping As Archimedes famously observed, if you put an object on a lever arm, it will ...