题目大意是Appleman每次将Toastman给他的Ni个数拆分成两部分后再还给Toastman,若Ni == 1则直接丢弃不拆分。而Toastman将每次获得的Mi个数累加起来作为分数,初始时Toastman直接获得N个数,求Toastman最后可以获得的最高分是多少。

这题简单的贪心,Appleman每次拆分的时候。将最小的一个数作为一部分,剩下的作为另外一部分,这样能够使得较大的数尽量多次參与累加。

#include <stdlib.h>
#include <stdio.h>
#include <algorithm> int values[500001];
long long sums[500001]; int compp(const void* a1, const void* a2)
{
return *((int*)a2) - *((int*)a1);
} int main()
{
#ifdef _DEBUG
freopen("e:\\in.txt", "r", stdin);
#endif // _DEBUG
int n;
scanf("%d", &n);
for (int i = 0; i < n;i++)
{
scanf("%d", &values[i]);
}
qsort(values, n, sizeof(int), compp);
sums[0] = values[0];
for (int i = 1; i < n;i++)
{
sums[i] = sums[i - 1] + values[i];
}
long long res = sums[n - 1];
for (int i = n - 1; i >= 1;i--)
{
res += sums[i];
}
printf("%I64d\n", res);
return 0;
}

Codeforces461A Appleman and Toastman 贪心的更多相关文章

  1. 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman

    题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...

  2. Codeforces 263C. Appleman and Toastman

    C. Appleman and Toastman time limit per test  2 seconds memory limit per test  256 megabytes input  ...

  3. codeforces 462C Appleman and Toastman 解题报告

    题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...

  4. CF 463A && 463B 贪心 && 463C 霍夫曼树 && 463D 树形dp && 463E 线段树

    http://codeforces.com/contest/462 A:Appleman and Easy Task 要求是否全部的字符都挨着偶数个'o' #include <cstdio> ...

  5. Codeforces Round #263 (Div. 2) A B C

    题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...

  6. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  7. CF#263

    昨天没打,今天写了一下,前三题都没有难度吧. A. Appleman and Easy Task time limit per test 1 second memory limit per test ...

  8. Codeforces Round #263 (Div. 2) proC

    题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. CodeForces 462B Appleman and Card Game(贪心)

    题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase ...

随机推荐

  1. es修改索引副本个数

    es修改索引副本个数 PUT index01/_settings { "number_of_replicas": 2 }

  2. 【Hadoop基础】hadoop fs 命令

    1,hadoop fs –fs [local | <file system URI>]:声明hadoop使用的文件系统,如果不声明的话,使用当前配置文件配置的,按如下顺序查找:hadoop ...

  3. CSS基础和布局复习

    table布局 div布局优势   浏览器支持完善   表现和结构分离   样式设计控制功能强大   可以继承,层叠处理 Transitional // 松散过度型 Strict //严格型 Fram ...

  4. angularjs中的数据绑定

    这是一个最简单的angularjs的例子,关于数据绑定的,大家可以执行一下,看看效果 <html ng-app> <head> <title>angularjs-i ...

  5. HashMap源代码阅读

    Map类结构 Java的集合类主要由两个接口派生出来,Collection和Map,上一节我们讨论过Collection接口结构,如今来看下Map接口. HashMap 一种存储键/值关联的数据结构 ...

  6. npm发包流程

    1.注册npm 账号 https://www.npmjs.com/signup 2.初始化npm项目 npm init 根据发的包进行填写: { "name": "wen ...

  7. mysql和redis之间互相备份

    http://code.google.com/p/redisql/wiki/Examples 项目地址:https://github.com/JakSprats/predis/blob/master/ ...

  8. some issues that you should be take care of when use the plupload module

    1. the config arguments 'browse_button' should not be a single element like button etc. because in i ...

  9. python 读取文件时报错: UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence

    UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 127: illegal multibyte sequence p ...

  10. VirtualBox虚拟机扩容

    1. 在VBox下增加储存 如图,未扩容前是40G 打开cmd命令行(win+r  输入cmd打开) 将目录切换到virtual的安装目录 cd C:\Program Files\Oracle\Vir ...