UVA1614(贪心)
Time Limit:3000MS | Memory Limit:Unknown | 64bit IO Format:%lld & %llu |
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 ( 1


) during i -th minute ( 1


), 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

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 ( 1n
100 000
). The second line of the input contains n integer numbers --
ai ( 1ai
i
).
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
排序之后贪心瞎搞。。。
/*************************************************************************
> 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(贪心)的更多相关文章
- UVA-1614 Hell on the Markets(贪心+推理) (有待补充)
题目大意:一个整数序列a,1≤a[i]≤i.问能否通过在一些元素前加上负号,使得整个序列和为0. 题目分析:贪心.贪心策略:每次都先选最大的元素加负号(或保留,不加负号). 贪心依据:对于1≤a[i] ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
- code vs 1098 均分纸牌(贪心)
1098 均分纸牌 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有 N 堆纸牌 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
随机推荐
- editplus运行php 配置
工具->配置用户工具->添加工具:Menu Text 改成runphp或者其他任名称.Command 安装的php.exe的地址.如D:\ wamp\php\php5.4.3\php.ex ...
- AOP:声明式事务管理流程
1. 注册BeanFactoryTransactionAttributeSourceAdvisor @EnableTransactionManagement --> @Import(Transa ...
- PHP 登录DEMO
logintest.php 页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...
- ALAssetsLibrary使用
在iOS中,我们调用摄像头和选择相册中的资源,我们可以使用:UIImagePickerController类来完成. 当然,我们也可以不使用UI的形式来访问iOS设备的相册资源. 那就是使用:AL ...
- Spring使用@Required注解依赖检查
Spring依赖检查 bean 配置文件用于确定的特定类型(基本,集合或对象)的所有属性被设置.在大多数情况下,你只需要确保特定属性已经设置但不是所有属性.. 对于这种情况,你需要 @Required ...
- Html基础知识详解
一定要做的符合客户要求,不是自己认为对的. 一.基础标签 1.1 大小颜色位置 <!DOCTYPE HTML> <html> <head> <meta htt ...
- ionic开发环境搭建之ios
前言 公司在做完ionic androud版后就开始做ios版,虽然ios的坑我觉得比起androud少了很多,但是作为第一次接触ios的我来说,环境实在太麻烦,从搭环境到打包一个正式版的ios ap ...
- svn使用经验---不断总结
删除文件或文件夹 svn rm 名字 --force svn ci (系统会提示输入提交日志) 执行完这两步后,才能被真正删除 添加文件或文件夹 svn add 文件名 --force ...
- IIS7 win7 x64 MVC部署
.net4.5已经装好,mvc4setup也装了,启动IIS后打开网页还是不能正常显示页面,404错误 最后发现把win7升级到SP1就正常了,具体是那个补丁修复的就不知道了
- 🌅 使用 Dawn 快速搭建 React 项目!
开发一个 React 项目,通常避免不了要去配置 Webpack 和 babel 之类,以支持 commonjs 或 es 模块及各种 es 新语法,及进行 jsx 语法的转义.当然也可以用 crea ...