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 ...
随机推荐
- [Cometoj#4 E]公共子序列_贪心_树状数组_动态规划
公共子序列 题目链接:https://cometoj.com/contest/39/problem/E?problem_id=1585 数据范围:略. 题解: 首先可以考虑知道了$1$的个数和$3$的 ...
- emacs 常用命令
C stands for Ctrl and M stands for Alt REFERENCE FORM EMACS TUTORIAL 表述不一定正确,仅供参考,主要是要多实践,一开始可能会不习惯 ...
- [转]史上最最最详细的手写Promise教程
我们工作中免不了运用promise用来解决异步回调问题.平时用的很多库或者插件都运用了promise 例如axios.fetch等等.但是你知道promise是咋写出来的呢? 别怕-这里有本promi ...
- mybatis 的一对一关联查询association
现在项目的列表查询数据需要查一个总数count, 如果直接写在同一个sql里面,会导致查询速度很慢, 因此,想到使用关联查询,例子如下: 附上代码: 其中遇到的坑哟: 1.association中的s ...
- 【51nod】2591 最终讨伐
[51nod]2591 最终讨伐 敲51nod是啥评测机啊,好几次都编译超时然后同一份代码莫名奇妙在众多0ms中忽然超时 这道题很简单就是\(M\)名既被诅咒也有石头的人,要么就把石头给没有石头被诅咒 ...
- (十)springMvc 校验
目录 文章目录 目录 @[toc] springMvc 校验 准备 踩坑 配置校验器 将校验器注入到适配器中 在 pojo 中配置校验规则 在 controller 层进行检验 获取错误信息 将错误信 ...
- php中连接tcp服务的三种方式
首先需要现有一个 tcp 服务,我们使用 php中的 socket 系列函数实现 <?php //创建socket套接字 $socket = socket_create(AF_INET, SOC ...
- python学习-1 编程语言的介绍
1.开发语言: 高级语言:Java.python.C#.PHP.Go.ruby.C++等等 低级语言:C.汇编语言 2.机器码和字节码 高级语言 ====>字节码 低级语言===>机器码 ...
- python3.5+installer 将.py 打包成.exe
(1)下载安装installer,不如我安装在D:\Program Files\Python35,安装完成后,在D:\Program Files\Python35\Scripts可以找到install ...
- 适合新手的160个creakme(三)
先跑一下,这个程序应该是有定时器,多久之后自动开启,测试一下输入,序列号以字母方式输入会出现类型不匹配,之后程序自动退出 但是如果以数字方式输入序列号,则会出现,Try Again,所以这里序列号应该 ...