Codeforces Round #587 (Div. 3) B. Shooting(贪心)
链接:
https://codeforces.com/contest/1216/problem/B
题意:
Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he will knock the cans down.
Vasya knows that the durability of the i-th can is ai. It means that if Vasya has already knocked x cans down and is now about to start shooting the i-th one, he will need (ai⋅x+1) shots to knock it down. You can assume that if Vasya starts shooting the i-th can, he will be shooting it until he knocks it down.
Your task is to choose such an order of shooting so that the number of shots required to knock each of the n given cans down exactly once is minimum possible.
思路:
贪心, 大的优先
代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4+10;
struct Node
{
int a, id;
bool operator < (const Node& that) const
{
return this->a > that.a;
}
}node[MAXN];
int n;
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
cin >> node[i].a, node[i].id = i;
sort(node+1, node+1+n);
int cnt = 0, sum = 0;
for (int i = 1;i <= n;i++)
{
sum += node[i].a*cnt+1;
cnt++;
}
cout << sum << endl;
for (int i = 1;i <= n;i++)
cout << node[i].id << ' ' ;
cout << endl;
return 0;
}
Codeforces Round #587 (Div. 3) B. Shooting(贪心)的更多相关文章
- Codeforces Round #202 (Div. 1) A. Mafia 贪心
A. Mafia Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...
- Codeforces Round #587 (Div. 3)
https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改 ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- Codeforces Round #180 (Div. 2) B. Sail 贪心
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
随机推荐
- 报表工具ActiveReports开发实例——物联网智能供水云平台
一.公司简介 山西汾西电子科技股份有限公司(以下简称:汾西电子)是经中国船舶重工集团批准,在原汾西重工电子科技公司基础上重组的专业从事智能电能表.水表.热量表及电动汽车充电设备研发生产的高科技公司. ...
- random、range和len函数的使用
random.range和len函数的使用 一.random函数 1.random.random()和random.Random(): import random num = random.rando ...
- eclipse scala Could not reserve enough space for object heap
[学习笔记] 防盗版实名手机尾号:73203 Could not reserve enough space for object heap 解决方法:下面的缩写中:一个是memory max(Xmx) ...
- lxml and 代理ip
pip install lxml 导包From lxml import etree 1. 注意这个是本地html就直接使用etree.parse即可 2. html_etree=etree.parse ...
- Scrapy爬虫-win7下创建运行项目
开始的时候,我只安装了python3.5,安装不了scrapy库,网上搜了一下说是scrapy不支持python3.x 然后,我就又安装了python2.7 为了,默认使用2.7,我在环境变量path ...
- .Net C# EF database first connectionstring
<connectionStrings> <add name="CupCreditCheckDB" connectionString="metadata= ...
- 浅谈后缀数组SA
这篇博客不打算讲多么详细,网上关于后缀数组的blog比我讲的好多了,这一篇博客我是为自己加深印象写的. 给你们分享了那么多,容我自私一回吧~ 参考资料:这位dalao的blog 一.关于求Suffix ...
- hdu 1151 最小路径覆盖
先说说最小路径覆盖的定义 定义:在一个有向图中,找出最少的路径,使得这些路径,经过每一个点,且每一个点只与一条路径相关联, 由上面得出: 1.一个单独的点是一个路径 2:如果有路径a,b,c....f ...
- 安装HAXM报错:failed to configure driver unknown error. failed to open driver 并提示数字签证不可用
1.安装微软补丁:https://www.microsoft.com/en-us/download/confirmation.aspx?id=46148 2.重启后重新安装HAXM
- 异常:Invalid character found in the request target. The valid characters are defined in RFC 3986
一.背景 事情是这样的,前几天做一个基本的数据库“增删改查”的需求,前端传参的方式是“JSON字符串”,后端接收到此参数后,使用阿里巴巴fastjson进行解析,然后入库.需求很简单吧,但是偏偏遇到问 ...