题目大意是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. mongodb pymongo.errors.CursorNotFound: Cursor not found, cursor id: 82792803897

    默认 mongo server维护连接的时间窗口是十分钟 默认 单次从 server获取数据是101条或者 大于1M小于16M的数据 所以默认情况下,如果10分钟内未能处理完数据,则抛出该异常. 解决 ...

  2. Microsoft Office Word 2007 文档结构图突然变小的解决办法

    前记: 一个word文档不知道修改了什么,突然发现文档结构图显示的文字变得非常的小了. 用ctrl+鼠标滚轮只能放大或是缩小行间距,对文字没有什么变化. 解决办法: 1.打开文档结构图 点击视图,勾选 ...

  3. 深入一点 让细节帮你和Fragment更熟络

    有一段时间没有写博客了.作为2017年的第一篇,初衷起始于前段时间一个接触安卓开发还不算太长时间的朋友聊到的一个问题: "假设,想要对一个Fragment每次在隐藏/显示之间做状态切换时进行 ...

  4. http协议中content-length 以及chunked编码分析

    转载请注明出处 http://blog.csdn.net/yankai0219/article/details/8269922 0.序 1.http/1.1协议中与chunked编码的相关字段 1)E ...

  5. xmpp 服务器配置 open fire for windows 及 spark 测试

    xmpp 服务器配置 open fire for windows 此文章为 XMPP windows服务器配置,使用的是 open fire 3.9.1.exe 1: 下载 open fire ope ...

  6. python -c 处理shell字符串

    $test="hello world" $python -c "print '$test'.split()[1]" world 或者 $test="h ...

  7. 如何打印加密的PDF文件?

    如何打印加密的PDF文件? Pdf加密了不让打印怎么办?? 下载Foxit PDF Editor以下是下载地址:http://www.orsoon.com/Soft/4865.html 用它打开加密的 ...

  8. Jquery重新学习之一[加载与属性html(),text(),val()]

    一:Jquery加载方式: 1:首先页面加载时马上响应JS代码如下运行(不一定要等所有的JS和图片加载完毕,就可以执行方法): $(document).ready(function(){ }); 另一 ...

  9. 查看客户端的IP地址,机器名,MAC地址,登陆名等信息

    查看客户端的IP地址,机器名,MAC地址,登陆名等信息 SELECT s.session_id,s.login_time,s.host_name,p.loginame,s.program_name,c ...

  10. java 线程安全集合

    ConcurrentMap 线程安全的HashMap CopyOnWriteArrayList 读多写少的线程安全的ArrayList,性能比vector好. ConcurrentLinkedQueu ...