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.
 
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
 
Output
For each case, output the final sum.
 
Sample Input
4
1 2 3 4
2
5 5
 
Sample Output
25
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 ;
}

最新文章

  1. 关于更新发布CSS和JS文件的缓存问题
  2. 手持机(Android)开发应用总结
  3. 从H264码流中获取视频宽高 (SPS帧)
  4. ios awakeFromNib 和 initWithCoder:
  5. ASP.NET页面动态添加js脚本
  6. Django数据库设计中字段为空的方式
  7. 使用js对中文进行gbk编码
  8. XIB 不能拖线的低级错误
  9. [原博客] POJ 2484 A Funny Game
  10. 建立Go工作环境
  11. python 中如何导入一个自己创建的模块
  12. android调用系统相机进行视频录制并保存到指定目录
  13. javascript的一些算法的实用小技巧
  14. MySQL InnoDB 事务实现过程相关内容的概述
  15. FileProvider的使用及应用更新时提示:解析包出错、失败等问题
  16. Brainfuck解析器(Python)
  17. jsplumb流程器使用2
  18. 在Windows Azure上创建ASP.NET MVC网站
  19. MySQL5.7.11免安装版的安装和配置:解决MYSQL 服务无法启动问题
  20. 美团店铺评价语言处理以及文本分类(logistic regression)

热门文章

  1. python3.7 装饰器
  2. B1013 数素数(20分)
  3. Scrapy的架构与原理的理解【转】
  4. Android四大组件之服务
  5. Androd安全——反编译技术完全解析
  6. POI-java下载excel-HSSFWorkbook
  7. loj2055 「TJOI / HEOI2016」排序
  8. laravel5.2总结--服务提供者,契约(Contracts)
  9. copy &amp; deepcopy
  10. js 遍历对象属性(for in、Object.keys、Object.getOwnProperty) 以及高效地输出 js 数组