hdu 2803 The MAX

来源:互联网 发布:人工智能屠宰场小女孩 编辑:程序博客网 时间:2024/03/29 09:02

The MAX

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2060    Accepted Submission(s): 895


Problem Description
Giving N integers, V1, V2,,,,Vn, you should find the biggest value of F.


Input
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.
 

Output
For each test case, output the biggest value of F you can find on a line.
 

Sample Input
21 20
 

Sample Output
4017
 解题思路:v数组进行从大到小的排序,将最大的元素乘以(2010-n)再加上(n-1)注意的是数组应定义为long long型
#include<stdio.h>#include<algorithm>#include<math.h>using namespace std;long long num[1010];int cmp(long  a,long  b){return a>b;}int main(){int  n;while(scanf("%d",&n),n){for(int i=1;i<=n;i++) {  scanf("%lld",&num[i]); } sort(num+1,num+n+1,cmp);         long long s=0;         s=(2010-n)*num[1];          for(int i=2;i<=n;i++)          {          s+=num[i];  }printf("%lld\n",s);}return 0;}





0 0
原创粉丝点击