Codeforces461A Appleman and Toastman 贪心
题目大意是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 贪心的更多相关文章
- 贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman
题目传送门 /* 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 */ /************************************************ Author :R ...
- Codeforces 263C. Appleman and Toastman
C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...
- codeforces 462C Appleman and Toastman 解题报告
题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得 ...
- CF 463A && 463B 贪心 && 463C 霍夫曼树 && 463D 树形dp && 463E 线段树
http://codeforces.com/contest/462 A:Appleman and Easy Task 要求是否全部的字符都挨着偶数个'o' #include <cstdio> ...
- Codeforces Round #263 (Div. 2) A B C
题目链接 A. Appleman and Easy Task time limit per test:2 secondsmemory limit per test:256 megabytesinput ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- CF#263
昨天没打,今天写了一下,前三题都没有难度吧. A. Appleman and Easy Task time limit per test 1 second memory limit per test ...
- Codeforces Round #263 (Div. 2) proC
题目: C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...
- CodeForces 462B Appleman and Card Game(贪心)
题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase ...
随机推荐
- 给出a的定义 -- 指针 和 数组
- (转) 问题解决:Apache: You don't have permission to access / on this server
问题解决:Apache: You don't have permission to access / on this server 转自:http://blog.csdn.net/crazyboy20 ...
- Visual Studio 2012安装VASSISTX插件后导致CPU高的解决的方法
笔者一直都喜欢用VAX插件来做C++的开发,但发现VS2012安装了VAX后,CPU占用超级高,有时界面卡死得很厉害.我卸了又装,升级最新版,都无论用. 直到有天.看到网友说:VS2012的sdf文件 ...
- 获取ArcGIS安装路径
在要素类进行符号化时,使用axSymbologyControl需要安装路径下的Style文件路径,在AE9.3+VS2008中是这样的: Microsoft.Win32.RegistryKey reg ...
- [置顶] ArcGIS Runtime SDKs 10.2 for iOS & Android& OS X发布
我们高兴的宣布:ArcGISRuntime SDKs 10.2 for iOS & Android & OS X正式发布!在10.2版本中,你可以在iOS.Android和Mac设备上 ...
- poj 3311 Hie with the Pie dp+状压
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4671 Accepted: 2471 ...
- QtGui.QFontDialog
The QtGui.QFontDialog is a dialog widget for selecting a font. #!/usr/bin/python # -*- coding: utf-8 ...
- DBA 需要知道N种对数据库性能的监控SQL语句
--DBA 需要知道N种对数据库性能的监控SQL语句 -- IO问题的SQL内部分析 下面的DMV查询可以来检查当前所有的等待累积值. Select wait_type, waiting_tasks_ ...
- js无缝滚动,不平滑(求高人指点)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- android使用achartengine 实现折线图
折线图的实现分为下边几个步骤: 1.第一步:数据的准备 XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset(); XYSeri ...