hdoj 2803 The MAX【简单规律题】
2015-11-05 20:39
162 查看
The MAX
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2062 Accepted Submission(s):
896
[align=left]Problem Description[/align]
Giving N integers, V1, V2,,,,Vn, you should find the
biggest value of F.
[align=left]Input[/align]
Each test case contains a single integer N
(1<=N<=100). The next line contains N integers, meaning the value of V1,
V2....Vn.(1<= Vi <=10^8).The input is terminated by a set starting with N
= 0. This set should not be processed.
[align=left]Output[/align]
For each test case, output the biggest value of F you
can find on a line.
[align=left]Sample Input[/align]
2
1 2
0
[align=left]Sample Output[/align]
4017
题解:找到这个数组中最大的数乘以上(2009-n+1)这个数组中其余的数全加上来即可
#include<stdio.h> #include<string.h> #include<algorithm> #define MAX 110 #define LL long long using namespace std; bool cmp(int a,int b) { return a>b; } int main() { int n,m,j,i; LL s[MAX]; LL sum; while(scanf("%d",&n),n) { sum=0; for(i=0;i<n;i++) scanf("%lld",&s[i]); sort(s,s+n,cmp); for(i=1;i<n;i++) sum+=s[i]; sum+=(s[0]*(2009-n+1)); printf("%lld\n",sum); } return 0; }
相关文章推荐
- 选择排序语法树
- leetcode15 3sum
- 在vector的循环中调用erase
- 优化的快速排序Java实现,有一块元素个数小于k后采用插入排序
- Linq读取XML
- String转换成int型
- JS---正则表达式练习
- Thunderbird使用发邮件模板
- 我的书单
- hdoj 1069 Monkey and Banana【dp】
- 解决yii框架中,使用参数化查询时,IN只能查询一个的代替方法
- iOS推送基本原理
- 用Thunderbird以HTML发邮件,收件人却总是收到文本邮件
- 329 (Div. 2) B 数学
- Introduction to Algorithm - Summary of Chapter 8 - Sorting in Linear Time
- java中如何创建自己的类加载器详解
- hdu3709(数位dp)
- OneThink框架的文章详情页分页
- ubuntu下软件管理
- cannot convert parameter 1 from 'const char [] ' to 'const wchar_t * '的解决方法