贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman
/*
贪心:每次把一个丢掉,选择最小的。累加求和,重复n-1次
*/
/************************************************
Author :Running_Time
Created Time :2015-8-1 13:20:01
File Name :A.cpp
*************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; typedef long long ll;
const int MAXN = 3e5 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int a[MAXN]; int main(void) { //Codeforces Round #263 (Div. 2) C. Appleman and Toastman
int n; ll sum, ans;
while (scanf ("%d", &n) == ) {
sum = ;
for (int i=; i<=n; ++i) {
scanf ("%d", &a[i]); sum += a[i];
}
if (n == ) {
printf ("%d\n", a[]); continue;
}
sort (a+, a++n);
ans = sum;
for (int i=; i<n; ++i) {
ans += sum; sum -= a[i];
}
printf ("%I64d\n", ans);
} return ;
}
贪心 Codeforces Round #263 (Div. 2) C. Appleman and Toastman的更多相关文章
- Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)
题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...
- Codeforces Round #263 (Div. 1) C. Appleman and a Sheet of Paper 树状数组暴力更新
C. Appleman and a Sheet of Paper Appleman has a very big sheet of paper. This sheet has a form of ...
- Codeforces Round #263 (Div. 2) A. Appleman and Easy Task【地图型搜索/判断一个点四周‘o’的个数的奇偶】
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #263 Div.1 B Appleman and Tree --树形DP【转】
题意:给了一棵树以及每个节点的颜色,1代表黑,0代表白,求将这棵树拆成k棵树,使得每棵树恰好有一个黑色节点的方法数 解法:树形DP问题.定义: dp[u][0]表示以u为根的子树对父亲的贡献为0 dp ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
随机推荐
- Mysql UPDATE 操作时含 Limit 注意事项
在update时,可以使用limit来设置,更新的条数,但下面这句sql语句是错误的. LIMIT ,; //错误提示:ERROR 1064 (42000): You have an error in ...
- Redis 配置【十】
参考:http://www.runoob.com/redis/redis-conf.html Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf. 你可以通过 CONF ...
- [HDU5709]Claris Loves Painting(动态开点线段树+合并)
题意:有n(<=1e5)个点的树,每个点都有颜色(颜色可能重复),有m(<=1e5)个询问,每次询问(x,d)问在x的子树中,与x的距离不超过d的节点有多少种不同的颜色.强制要求在线. 分 ...
- Eclipse使用Maven时,修改默认中央仓库后的配置报错找不到包的问题解决
一般在公司内容配置Maven时会在settings.xml文件下配置私服nexus地址,那么修改完之后在Eclipse中如果不指定用户目录级别的settings.xml文件会出现找不到包的问题. se ...
- Nginx+Keepalived(双机热备)搭建高可用负载均衡环境(HA)
原文:https://my.oschina.net/xshuai/blog/917097 摘要: Nginx+Keepalived搭建高可用负载均衡环境(HA) http://blog.csdn.ne ...
- FDMemTable内存表操作
unit Umemtable; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System ...
- python 进程内存增长问题, 解决方法和工具
转载:http://drmingdrmer.github.io/tech/programming/2017/05/06/python-mem.html#pyrasite-%E8%BF%9E%E6%8E ...
- UVa 10534 Wavio Sequence (最长递增子序列 DP 二分)
Wavio Sequence Wavio is a sequence of integers. It has some interesting properties. · Wavio is of ...
- STL非变易算法
非变易算法:原则上不会变更操作数据的算法. [1] for_each:逐个容器元素,原型for_each(InputIter first, InputIter last, Function f) ...
- netty4与protocol buffer结合简易教程
各项目之间通常使用二进制进行通讯,占用带宽小.处理速度快~ 感谢netty作者Trustin Lee.让netty天生支持protocol buffer. 本实例使用netty4+protobuf-2 ...