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 ...
随机推荐
- Nginx之rewrite四种flag
利用nginx的rewrite命令,可以实现URL的重写,可在nginx配置文件的server.location.if部分使用,对于rewrite有四种不同的flag. redirect:返回302临 ...
- python+pycharm+django admin css样式出问题
最近打算学习一下Python,基础知识有了大概的了解,想上手搞搞东西. 我用的python 3.5+pycharm+django 1.11.2 在使用Django,打开127.0.0.1:8000/a ...
- golang之工厂模式
说明: golang的结构体没有构造函数,通常可以使用工厂模式来解决这个问题 如果包里面的结构体变量首字母小写,引入后,不能直接使用,可以工厂模式解决: ch1.go package ch1 type ...
- Devexpress xaf针对某个用户登录后在面板中设置导航无效的解决方法
Devexpress xaf框架生成的项目默认情况下导航栏是显示在左侧,有时候我们用某个账户登录后,发现导航栏无法显示在左侧,操作十分不方便.我们可以去数据库删除当前登录用户的自定义布局 解决方法如下 ...
- Istio技术与实践01: 源码解析之Pilot多云平台服务发现机制
服务模型 首先,Istio作为一个(微)服务治理的平台,和其他的微服务模型一样也提供了Service,ServiceInstance这样抽象服务模型.如Service的定义中所表达的,一个服务有一个全 ...
- ButterKnife8.5.1最新版本使用详细步骤
android studio中使用方法: 1.build.gradle(Modul: app) 添加dependencies{ compile 'com.jakewharton:butterknife ...
- ES6用来判断数值的相关函数
最近在学习ES6的基础知识,整理了一下ES6用来判断数值的相关函数 Math.sign() =>判断正负数的函数 Math.trunc() =>取整函数 Number.isInteger( ...
- javaIO——概述
以前看java书,都将IO作为一个大的章节甚至模块来编写,可见IO在java语言中的重要性. java的流按功能和处理的目标数据不同可以分为字节流和字符流.字符流处理的基本数据单元是字符:字节流处理的 ...
- sip呼叫里SDP的一些字段的含义
v=0 o=- 1 0 IN IP4 164.135.25.51 #local ip ,即本机SIP信令交互地址 s=SNS call #用于传递会话主题 c=IN IP4 164.135.25.51 ...
- 1 简介mvp模式
1 模型-视图-表示器也称为监视控制器模式 ,如下图表示 2 mvp 模式希望通过表示器(presenter)来关联网页,而不必在他们之间建立严格的 3 一个简单的mvp架构的例子 public ...