Codeforces 462C C. Appleman and Toastman【贪心】
来源:互联网 发布:安卓便签软件 编辑:程序博客网 时间:2024/06/09 13:48
题目大意:
现在有一个长度为N的序列,按照游戏规则去做,问最多能够获得多少分。
思路:
很显然我们希望删除的数字永远都是最小的那个,所以我们将序列进行排序,然后从大到小考虑每个数字对结果的贡献的总价值即可。
Ac代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[350000];int main(){ int n; while(~scanf("%d",&n)) { __int64 sum=0; for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i]; sort(a+1,a+1+n); if(n==1) { printf("%d\n",a[1]); continue; } __int64 output=0; __int64 cnt=2; for(int i=1;i<=n;i++) { output+=cnt*a[i]; if(i<=n-2)cnt++; } printf("%I64d\n",output); }}
阅读全文
0 0
- CodeForces 462C Appleman and Toastman 贪心
- Codeforces 462C C. Appleman and Toastman【贪心】
- CodeForces-462C Appleman and Toastman
- 【CODEFORCES】 C. Appleman and Toastman
- 462C - Appleman and Toastman
- Codeforces Round #263 (Div. 2) C. Appleman and Toastman(贪心)
- Codeforces 461A Appleman and Toastman(贪心)
- CodeForces 461A Appleman and Toastman(贪心)
- Codeforces Round #263 (Div. 2)C. Appleman and Toastman
- Codeforces Round #263(div2)C. Appleman and Toastman
- Codeforces Round #263 (Div. 2) C. Appleman and Toastman
- Codeforces Round #263 (Div. 2)-C. Appleman and Toastman
- Codeforces Round #263 (Div. 2)-C. Appleman and Toastman
- CF 263div2 C. Appleman and Toastman
- Codeforces461A Appleman and Toastman 贪心
- 【Codeforces Round 263 (Div 2)C】【贪心 哈弗曼思维】Appleman and Toastman 每个非1size子树延展为2子树的最大权
- Codeforces-461A Appleman and Toastman
- Appleman and Toastman - CodeForces 461 A 水题
- 合并分支到Master
- MySQL默认约束
- Codeforces Round #436 (Div. 2) A-D题解
- C语言学习笔记——前言
- 1010 radix
- Codeforces 462C C. Appleman and Toastman【贪心】
- POJ 2109.Power of Cryptography
- Leetcode—3.Longest Substring Without Repeating Characters
- 使用Stanford Parser进行句法分析
- 前端工具——Bower
- linux中的echo命令
- Java8新特性 --- Lambda表达式教程
- Ubuntu15.10安装小结
- cookie和session