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 ...
随机推荐
- (模板)poj1681 高斯消元法求异或方程组(无解、唯一解、多解)
题目链接:https://vjudge.net/problem/POJ-1681 题意:类似于poj1222,有n×n的01矩阵,翻转一个点会翻转其上下左右包括自己的点,求最少翻转多少点能使得矩阵全0 ...
- appium+python教程1
Python3+Appium安装使用教程 一.安装 我们知道selenium是桌面浏览器自动化操作工具(Web Browser Automation) appium是继承selenium自动化思想旨在 ...
- Mybatis 批量操作以及多参数操作遇到的坑
查考地址:https://blog.csdn.net/shengtianbanzi_/article/details/80147134 待整理中......
- Kubernetes---资源控制器之ReplicationController、ReplicaSet和Deployment
1.ReplicationController和ReplicaSet介绍 RC(ReplicationController)主要的作用就是用来确保容器应用的副本数始终保持在用户定义的副本数.即如果有容 ...
- (七)RequestMapping 和 Controller方法
文章目录 @[toc] RequestMapping功能 controller 方法返回值 RequestMapping功能 url映射 在定义 Controller 的,我们在方法上面,使用 @Re ...
- QT 线程的使用(继承QThread)
对于多线程而言,要注意资源的同步和互斥问题,但对于单独的一个线程,则只需要对它的run方法进行重写. 下面实现了一个简单的线程 widget.h文件 #ifndef WIDGET_H #define ...
- select key from table 一直出错
key和keys 为mysql 关键字,数据库设计字段的时候尽量避免
- 第一章 MIZ701 VIVADO 搭建SOC最小系统HelloWorld
本章内容是MIZ701中的第五章,本来也是要过渡一下FPGA部分的,但是由于MIZ701没有单独提供PL部分的晶振时钟,时钟必须通过PS产生,所以本章内容作为Miz701的第一章内容.本章的目的是 ...
- Centos7搭建在线yum源
1: 首先关闭防护墙或者设置规则通过且关闭selinux Systemctl diablefirewalld 永久关闭防火墙 vim/etc/sysconfig/selinux 并修改SELINUX ...
- 并不对劲的CF1245E&F:Cleaning Ladders
CF1245 E. Hyakugoku and Ladders 题目大意 有一个10 \(\times\) 10的网格,你要按这样的路径行走: 网格中有一些单向传送门,每个传送门连接的两个格子在同一列 ...