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. 91网漏洞打包#越权+爆破+存储xss可打cookie

    漏洞一.主站存在登录口爆破 抓包,爆破一下 爆破成功 漏洞二.检测app时一处存储xss 在app登录后 我要提问那里插入xss 然后弹窗 可以打到cookie 漏洞三.app个人资料处平行越权可查看 ...

  2. bzoj 1051 强连通分量

    反建图,计算强连通分量,将每个分量看成一个点,缩点后的图是一个DAG,如果是一棵树,则根代表的连通分量的大小就是答案,否则答案为0. 收获: 图的东西如果不好解决,可以尝试缩点(有向图将每个强连通分量 ...

  3. CROC 2016 - Elimination Round (Rated Unofficial Edition) B. Mischievous Mess Makers 贪心

    B. Mischievous Mess Makers 题目连接: http://www.codeforces.com/contest/655/problem/B Description It is a ...

  4. MVC 3.0错误 HTTP 404您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。

    MVC3.0框架开发项目: 有时在程序运行的时候会出现“HTTP 404.您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用.请检查以下 URL 并确保其拼写正确.”的错 ...

  5. JSoup 用法详解

    清单 1 // 直接从字符串中输入 HTML 文档 String html = "<html><head><title> 开源中国社区 </titl ...

  6. HDU 1159 &amp;&amp; POJ 1458

    最长公共子序列.状态转移方程见代码. #include <iostream> #include <cstdio> #include <cstring> using ...

  7. Linux下查找命令(收集整理)

    原文:http://blog.csdn.net/sunstars2009918/article/details/8510878 一.Linux查找文件的相关命令 常 用 命 令 简要中文说明 程序所在 ...

  8. 关于MORMOT跨平台

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

  9. Gulp插件autoprefixer的使用

    1.创建:gulpfile.js //引入插件 var gulp = require('gulp'); var autoprefixer = require('gulp-autoprefixer'); ...

  10. ajax成功返回数据中存在多余字符的处理

    ajax里有需要判断反馈的字符串是否为“ok”,在浏览器里调试,看到返回的内容明明是“ok”,但是if(“ok”==data)判断为false,用alert打印内容也是ok,但是打印长度的时候却是3. ...