链接:

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(贪心)的更多相关文章

  1. 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 ...

  2. Codeforces Round #587 (Div. 3)

    https://codeforces.com/contest/1216/problem/A A. Prefixes 题意大概就是每个偶数位置前面的ab数目要相等,很水,被自己坑了 1是没看见要输出修改 ...

  3. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  4. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  5. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  6. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  7. 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 ...

  8. Codeforces Round #374 (Div. 2) B. Passwords 贪心

    B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...

  9. Codeforces Round #303 (Div. 2) C. Woodcutters 贪心

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...

随机推荐

  1. The Maze II

    There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolli ...

  2. go 计算 MD5

    Golang的加密库都放在crypto目录下,其中MD5库在crypto/md5包中,该包主要提供了New和Sum函数 直接调用md5计算 package main import ( "cr ...

  3. 图片压缩java工具类

    package com.net.util; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.Fil ...

  4. 如何拿到美团offer的

    美团,我是在拉勾网上投的简历,之前也投过一次,简历都没通过删选,后来让学姐帮我改了一下简历,重新投另一个部门,获得了面试机会.10月23日,中午HR打电话过来预约了下午4点半面试,说会在线写代码,让我 ...

  5. ObjectMapper 对象和json相互转换

    一.ObjectMapper ObjectMapper类是Jackson库的主要类.它提供一些功能将转换成Java对象匹配JSON结构,反之亦然.它使用JsonParser和JsonGenerator ...

  6. 如何判断你的windows系统是32位还是64位?

    [学习笔记] 如 何判断你的windows系统是32位还是64位? java -version时,如果没有64就是32位的.eclipse.ini中如果没有64,就是32位的.但是我们的ini文件里面 ...

  7. C++ Primer 5th Chap1.Getting Started

    在CommandPrompt上:(即cmd) 假定文件名为prog1.cc: 编译:$Compiler'sName prog1.cc 打开(prog1.exe):$prog1 打开(在当前目录):$. ...

  8. 爬虫-selenium 模块-02

    目录 selenium 模块 chromedriver 浏览器驱动下载与存放 PhantomJS 无界面浏览器 标签元素查找方法 xpath 格式用法 获取标签属性 等待元素被加载 元素交互操作 点击 ...

  9. 【leetcode】287. 寻找重复数

    题目链接:传送门 题目描述: 给定一个数组 nums 包含 n + 1 个整数,每个整数在 1 到 n 之间,包括 1 和 n.现在假设数组中存在一个重复的数字,找到该重复的数字. 注意 不能修改数组 ...

  10. MySQL 聚合函数(一)聚合(组合)函数概述

    MySQL版本:5.7+ 本节介绍对值的集合进行操作的组合(聚合)函数.翻译自:Aggregate (GROUP BY) Function Descriptions 一.MySQL 5.7中的聚合函数 ...