贪心/CodeForces 461A Appleman and Toastman

 1 #include<cstdio>
 2 #include<algorithm>
 3 using namespace std;
 4 long long  a[300010];
 5 long long n;
 6 int main()
 7 {
 8     scanf("%lld",&n);
 9     for (long long i=1;i<=n;i++) scanf("%lld",&a[i]);
10     sort(a+1,a+n+1);
11     long long ans=0;
12     for (int i=1;i<n;i++) ans+=a[i]*(i+1);
13     ans+=a[n]*n;
14     printf("%lld\n",ans);
15     return 0;
16 }
时间: 2024-08-09 19:57:35

贪心/CodeForces 461A Appleman and Toastman的相关文章

Codeforces 263C. Appleman and Toastman

C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Appleman and Toastman play a game. Initially Appleman gives one group of nnumbers to the Toastman, then they start

codeforces 462C Appleman and Toastman 解题报告

题目链接:http://codeforces.com/problemset/problem/461/A 题目意思:给出一群由 n 个数组成的集合你,依次循环执行两种操作: (1)每次Toastman得到一个集合,他计算所有数的和,并且将它加入到score里.之后他将这个集合传给Appleman. (2)Appleman得到的集合如果只有一个数,就把它弃之,否则将这个集合分成 两个不相交且不空的集合,传回给Toastman. 这些操作不断执行直到集合个数变为0,也就是通过使集合都变成只有一个元素而

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

题目传送门 1 /* 2 贪心:每次把一个丢掉,选择最小的.累加求和,重复n-1次 3 */ 4 /************************************************ 5 Author :Running_Time 6 Created Time :2015-8-1 13:20:01 7 File Name :A.cpp 8 *************************************************/ 9 10 #include <cstdio>

Codeforces 461B Appleman and Tree(木dp)

题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k条边,使得树变成k+1个联通分量.保证每一个联通分量有且仅有1个黑色节点.问有多少种切割方法. 解题思路:树形dp,dp[i][0]和dp[i][1]分别表示子树一下的切割方法中,i节点所在联通块不存在黑节点和已经存在一个黑节点的方案数. #include <cstdio> #include &l

Codeforces 461B Appleman and Tree(树形dp)

题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每个节点的父亲节点,以及每个点的颜色(0表示白色,1表示黑色),切断这棵树的k条边,使得树变成k+1个联通分量,保证每个联通分量有且仅有1个黑色节点.问有多少种分割方法. 解题思路:树形dp,dp[i][0]和dp[i][1]分别表示子树一下的分割方法中,i节点所在联通块不存在黑节点和已经存在一个黑节点的方案数. #include <cstdio> #include <c

Codeforces 461C Appleman and a Sheet of Paper(模拟)

题目链接:Codeforces 461C Appleman and a Sheet of Paper 题目大意:就是一个叠被子的过程,穿插着询问一段区间上被子的单位厚度. 解题思路:用前缀和数组模拟即可.因为对于折超过一半的处理为将令一半叠上来,所以需要变量记录当前被子的正反状态.处理好下标关系即可. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const

CodeForces 462B Appleman and Card Game(贪心)

题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards

Codeforces461A Appleman and Toastman 贪心

题目大意是Appleman每次将Toastman给他的Ni个数拆分成两部分后再还给Toastman,若Ni == 1则直接丢弃不拆分.而Toastman将每次获得的Mi个数累加起来作为分数,初始时Toastman直接获得N个数,求Toastman最后可以获得的最高分是多少. 这题简单的贪心,Appleman每次拆分的时候.将最小的一个数作为一部分,剩下的作为另外一部分,这样能够使得较大的数尽量多次參与累加. #include <stdlib.h> #include <stdio.h>

Codeforces 263B. Appleman and Card Game

B. Appleman and Card Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's