hdu 4989(水题)
2024-08-30 03:18:17
Summary
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 835 Accepted Submission(s): 424
Problem Description
Small
W is playing a summary game. Firstly, He takes N numbers. Secondly he
takes out every pair of them and add this two numbers, thus he can get
N*(N - 1)/2 new numbers. Thirdly he deletes the repeated number of the
new numbers. Finally he gets the sum of the left numbers. Now small W
want you to tell him what is the final sum.
W is playing a summary game. Firstly, He takes N numbers. Secondly he
takes out every pair of them and add this two numbers, thus he can get
N*(N - 1)/2 new numbers. Thirdly he deletes the repeated number of the
new numbers. Finally he gets the sum of the left numbers. Now small W
want you to tell him what is the final sum.
Input
Multi test cases, every case occupies two lines, the first line contain n, then second line contain n numbers a1, a2, ……an separated by exact one space. Process to the end of file.
[Technical Specification]
2 <= n <= 100
-1000000000 <= ai <= 1000000000
[Technical Specification]
2 <= n <= 100
-1000000000 <= ai <= 1000000000
Output
For each case, output the final sum.
Sample Input
4
1 2 3 4
2
5 5
1 2 3 4
2
5 5
Sample Output
25
10
10
开long long 就好。
#include<iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = ;
long long a[N],b[N*N];
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
}
int id = ;
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
b[id++] = a[i]+a[j];
}
}
sort(b,b+id);
long long sum = b[];
for(int i=;i<id;i++){
if(b[i]==b[i-]) continue;
sum=sum+b[i];
}
printf("%lld\n",sum);
}
return ;
}
最新文章
- 关于更新发布CSS和JS文件的缓存问题
- 手持机(Android)开发应用总结
- 从H264码流中获取视频宽高 (SPS帧)
- ios awakeFromNib 和 initWithCoder:
- ASP.NET页面动态添加js脚本
- Django数据库设计中字段为空的方式
- 使用js对中文进行gbk编码
- XIB 不能拖线的低级错误
- [原博客] POJ 2484 A Funny Game
- 建立Go工作环境
- python 中如何导入一个自己创建的模块
- android调用系统相机进行视频录制并保存到指定目录
- javascript的一些算法的实用小技巧
- MySQL InnoDB 事务实现过程相关内容的概述
- FileProvider的使用及应用更新时提示:解析包出错、失败等问题
- Brainfuck解析器(Python)
- jsplumb流程器使用2
- 在Windows Azure上创建ASP.NET MVC网站
- MySQL5.7.11免安装版的安装和配置:解决MYSQL 服务无法启动问题
- 美团店铺评价语言处理以及文本分类(logistic regression)
热门文章
- python3.7 装饰器
- B1013 数素数(20分)
- Scrapy的架构与原理的理解【转】
- Android四大组件之服务
- Androd安全——反编译技术完全解析
- POI-java下载excel-HSSFWorkbook
- loj2055 「TJOI / HEOI2016」排序
- laravel5.2总结--服务提供者,契约(Contracts)
- copy &; deepcopy
- js 遍历对象属性(for in、Object.keys、Object.getOwnProperty) 以及高效地输出 js 数组