UVA - 1614 Hell on the Market(贪心)
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<tex2html_verbatim_mark> contracts for i<tex2html_verbatim_mark> -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<tex2html_verbatim_mark> contracts ( 1 InputThe input file contains several test cases, each of them as described below. The first line of the input contains the single integer number n<tex2html_verbatim_mark> ( 1 OutputFor 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<tex2html_verbatim_mark> numbers -- bi<tex2html_verbatim_mark> . Sample Input4 Sample OutputNo 一组数据,选择其中的一半的数变成负数,加上另一半可以和为0 |
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long sum;
int t;
int f[];
struct node
{
int zg;
int id;
};
node a[];
int cmp(node x,node y)
{
return x.zg>y.zg;
}
int main()
{
while(cin>>t)
{
long long sum=;
for(int i=; i<t; i++)
{
cin>>a[i].zg;
a[i].id=i;
f[i]=-;
sum+=a[i].zg;
}
if(sum%||t==) cout<<"No"<<endl;
else
{
cout<<"Yes"<<endl;
sort(a,a+t,cmp);
int s=;
for(int i=; i<t; i++)
{
if(s+a[i].zg<=sum/)
{
s+=a[i].zg;
f[a[i].id]=;
if(s==sum/)
break;
}
}
cout<<f[];
for(int i=; i<t; i++)
{
cout<<' '<<f[i];
}
cout<<endl;
}
}
return ;
}
UVA - 1614 Hell on the Market(贪心)的更多相关文章
- UVa 1614 Hell on the Markets (贪心+推理)
题意:给定一个长度为 n 的序列,满足 1 <= ai <= i,要求确实每一个的符号,使得它们和为0. 析:首先这一个贪心的题目,再首先不是我想出来的,是我猜的,但并不知道为什么,然后在 ...
- uva 1614奇怪的股市(归纳法证明,贪心)
uva 1614奇怪的股市(归纳法证明,贪心) 输入一个长度为n的序列a,满足\(1\le a_i\le i\),要求确定每个数的正负号,使得所有数的总和为0.例如a={1, 2, 3, 4},则4个 ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- uva 1153 顾客是上帝(贪心)
uva 1153 顾客是上帝(贪心) 有n个工作,已知每个工作需要的时间q[i]和截止时间d[i](必须在此前完成),最多能完成多少个工作?工作只能串行完成,第一项任务开始的时间不早于时刻0. 这道题 ...
- UVA 1614 - Hell on the Markets 奇怪的股市(贪心,结论)
先证明一个结论吧,对于1≤ai≤i+1,前面ai个数一定可以凑出1~sum[i]中的任意一个数. 对于i=1显然成立, 假设对于i=k结论成立,那么对于i=k+1来说,只要证明sum[k]+i,1≤i ...
- 【uva 1614】Hell on the Markets(算法效率--贪心)
题意:有一个长度为N的序列A,满足1≤Ai≤i,每个数的正负号不知.请输出一种正负号的情况,使得所有数的和为0.(N≤100000) 解法:(我本来只想静静地继续做一个口胡选手...←_← 但是因为这 ...
- 紫书 习题8-10 UVa 1614 (贪心+结论)
这道题我苦思冥想了一个小时, 想用背包来揍sum/2, 然后发现数据太大, 空间存不下. 然后我最后还是去看了别人的博客, 发现竟然有个神奇的结论-- 幸好我没再钻研, 感觉这个结论我肯定是想不到的- ...
- UVA - 1614 Hell on the Markets(奇怪的股市)(贪心)
题意:输入一个长度为n(n<=100000)的序列a,满足1<=ai<=i,要求确定每个数的正负号,使得所有数的总和为0. 分析: 1.若总和为0,则未加符号之前,所有数之和必为偶数 ...
- UVA 538 - Balancing Bank Accounts(贪心)
UVA 538 - Balancing Bank Accounts 题目链接 题意:给定一些人的欠钱关系,要求在n-1次内还清钱,问方案 思路:贪心,处理出每一个人最后钱的状态,然后直接每一个人都和最 ...
随机推荐
- [Locked] Largest BST Subtree
Largest BST Subtree Given a binary tree, find the largest subtree which is a Binary Search Tree (BST ...
- 《Linear Algebra and Its Applications》-chaper3-行列式-从一个逆矩阵算法证明引入的行列式
这一章节开始介绍线性代数中另外一个基本概念——行列式. 其实与矩阵类似,行列式也是作为简化表述多项式的一种工具,关于行列式的历史渊源,有如下的介绍. 在介绍逆矩阵的时候,我们曾提及二阶矩阵有一个基于矩 ...
- 对Spring的一些理解
最近在复习一些关于框架的概念性问题,主要是为了最近的面试,怕被问到这些概念性的问题.不过在真正做开发的时候还是要好好理解这些框架的基本原理,以及它们的工作流程.这样,我们才能更好的使用这些框架.下面就 ...
- Intellij 快捷键大全
Intellij IDEA的快捷键非常好用,能大大提高我们的开发速度.这里列举了一些常用的快捷键. 快速查找: Ctrl+N 查找类 Ctrl+R 替换当前窗口的文本 Ctrl+F 当前代码中查 ...
- kafka单机安装配置
1.下载kafka wget https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.2.1/kafka_2.9.2-0.8.2.1.tgz 2.解 ...
- 一个IT男的创业感言
2014年的一月 我和高中的一个同学開始人生的第一次创业.就写点第一次创业的经验吧! 创业的最初 须要心中大概有个规划 这个规划可能是非常粗糙的 但大的方向一定要有.详细就是你进入的行业 行业已经存在 ...
- Android系统移植与驱动开发--第三章 Git使用入门及在学习中有感
第三章 Git使用入门 使用Git的目的是减少各种版本的Linux的压缩大小,提供源代码在Linux上进行编译. 在这一个章节中,其实就是关键步骤的操作,虽然Git与我们学习的android没有很大的 ...
- POJ 2049 Finding Nemo
Finding Nemo Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 8631 Accepted: 2019 Desc ...
- Python之路,Day14 - It's time for Django
Python之路,Day14 - It's time for Django 本节内容 Django流程介绍 Django url Django view Django models Django ...
- Python中的map()函数和reduce()函数的用法
Python中的map()函数和reduce()函数的用法 这篇文章主要介绍了Python中的map()函数和reduce()函数的用法,代码基于Python2.x版本,需要的朋友可以参考下 Py ...