hdoj 2803 The MAX【简单规律题】

The MAX

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


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
2
1 2
0
 

 

Sample Output
4017
 
题解:找到这个数组中最大的数乘以上(2009-n+1)这个数组中其余的数全加上来即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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;
}

  

posted @   非我非非我  阅读(209)  评论(0编辑  收藏  举报
编辑推荐:
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· Vite CVE-2025-30208 安全漏洞
· 《HelloGitHub》第 108 期
· MQ 如何保证数据一致性?
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
点击右上角即可分享
微信分享提示