题目大意是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. spring mvc--默认都使用了哪些bean

    在MVC中默认使用的bean都定义在了 org.springframework.web.servlet下的DispatcherServlet.properties 下载源文件后可查看到默认bean定义 ...

  2. 彻底领悟javascript中的exec与match方法

    exec是正则表达式的方法,而不是字符串的方法,它的参数才是字符串,如下所示: var re=new RegExp(/\d/); re.exec( "abc4def" ); //或 ...

  3. 会说话的HTML--语义化杂谭-TGideas-腾讯游戏官方设计团队

    家里有个熊孩子,经常会有一些意想不到的事情发生:回家的时候,他会笑呵呵冲过来,大声喊着“臭爸爸”:你让他把鞋穿上,他会提起鞋子往楼下扔...在小孩的世界里,他虽然会说话,但不一定明白其中的意思,不能正 ...

  4. LDA基本介绍以及LDA源码分析(BLEI)

    基本介绍: topic model,主题模型介绍:http://www.cnblogs.com/lixiaolun/p/4455764.html  以及 (http://blog.csdn.net/h ...

  5. 首先不谈C语言,我们先来谈谈编程工具

    系统环境: 推荐Windows xp sp1 软件: Tb2.0或3.0 推荐理由:最好的一个系统环境 系统环境: 推荐Windows xp/ Windows 7/ Windows 8.1/Windo ...

  6. Jquery重新学习之三[属性addClass(),removeClass(),toggleClass()]

    1:属性.addClass(class|fn)及.removeClass(class|fn) 1.1 .addClass(class) 参数class一个或多个要添加到元素中的CSS类名,请用空格分开 ...

  7. mysql 流程函数 存储引擎 InnoDB简单特性

    建表及插入数据语句: mysql> create table salary(userid int,salary decimal(9,2)); Query OK, 0 rows affected ...

  8. UITextView 的使用

    直接上代码: // // RootViewController.m // UIText_test // // #import "RootViewController.h" #imp ...

  9. 从P1到P7——我在淘宝这7年 - 子柳撰写

    http://kb.cnblogs.com/page/132752/来自博客园的整理版本,作者是子柳,博客地址:http://blog.sina.com.cn/calvinzhaoc (一) 2011 ...

  10. spring 3.0系统集成webservice

    spring 3.0系统集成webservice,踩了很多坑以后总算成功了,故写下这篇博客以记录. 1.准备jar包 由于项目是spring3.0,所以应该要使用cxf 2.7版本才可以成功配置,高版 ...