题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989

题目意思:给出 n 个数,然后将这些数两两相加,得到 n*(n-1) /2 对和,把重复的和去掉,最后相加起来。

  用STL中的set可以好方便的做出来,因为 insert 的时候它会自动去除重复的。记得要用 long long 或 int64,因为 -1000000000 <= ai <= 1000000000 !

  

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std; typedef __int64 LL;
const int maxn = + ;
LL a[maxn];
set<LL> s;
set<LL>::iterator ps; int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= maxn; i++)
s.clear();
for (int i = ; i < n; i++)
scanf("%I64d", &a[i]);
for (int i = ; i < n; i++)
{
for (int j = i+; j < n; j++)
s.insert(a[i] + a[j]);
}
LL ans = ;
for (ps = s.begin(); ps != s.end(); ps++)
ans += *ps;
printf("%I64d\n", ans);
}
return ;
}

BestCoder8 1001.Summary(hdu 4989) 解题报告的更多相关文章

  1. BestCoder17 1001.Chessboard(hdu 5100) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5100 题目意思:有一个 n * n 的棋盘,需要用 k * 1 的瓷砖去覆盖,问最大覆盖面积是多少. ...

  2. BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150 题目意思:就是直接求素数. 不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊---- ...

  3. BestCoder19 1001.Alexandra and Prime Numbers(hdu 5108) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5108 题目意思:给出一个数正整数 N,N <= 1e9,现在需要找出一个最少的正整数 M,使得 ...

  4. BestCoder13 1001.Beautiful Palindrome Number(hdu 5062) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5062 题目意思:给出 N,找出 1 - 10^N 中满足 Beautiful Palindrome N ...

  5. BestCoder12 1001.So easy(hdu 5058) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5058 (格式有点问题,为了方便阅读---整个复制下来吧) 题目意思:给出两个长度都为 n 的集合你,问 ...

  6. BestCoder10 1001 Revenge of Fibonacci(hdu 5018) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 题目意思:给出在 new Fibonacci 中最先的两个数 A 和 B(也就是f[1] = A ...

  7. BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...

  8. BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4985 题目意思:有 n 个数,对于第 i 个数给出 σ(i) 的值.求出互不相交的循环的个数,并输出每 ...

  9. BestCoder3 1001 Task schedule(hdu 4907) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4907 题目意思:给出工作表上的 n 个任务,第 i 个任务需要 ti 这么长的时间(持续时间是ti ~ ...

随机推荐

  1. 在nodejs下express 从安装到运行的全过程

    安装过程: npm install -gd express  npm install -g express-generator  express -V //查看版本,现在一般都是4.x系列的 expr ...

  2. Html书写规范

    #cnblogs_post_body ol { padding-left: 0px; } body { line-height: 1.6; } body, th, td, button, input, ...

  3. [译]Bundling and Minification

    原文:http://www.asp.net/mvc/overview/performance/bundling-and-minification============================ ...

  4. 【AngularJS】—— 9 自定义过滤器

    AngularJS另一个特点就是提供了过滤器,可以通过操作UNIX下管道的方式,操作数据结果. 通过使用管道,可以便于双向的数据绑定中视图的展现. 过滤器在处理过程中,将数据变成新的格式,而且可以使用 ...

  5. Thank you for your resubmission. Performance - 2.3.10 We noticed that your app or its metadata includes irrelevant third-party platform information. Specifically, Android logo is mentioned in the

    被拒很多次,各种修改,最后发现是提交的时候,含有安卓的图标!欲哭无泪呀! Thank you for your resubmission. Performance - 2.3.10 We notice ...

  6. JSP中根据不同的条件显示不一样的格式

    在做项目中遇到这样的场景: 当查询到记录时,需要将记录的字段作为下拉列表,让用户选择使用,即显示的是下拉列表. 当没有查询到记录时,则让用户手工填写该值,即显示的是文本框. 前段jsp使用if标签如下 ...

  7. 北京程序员 VS 硅谷程序员(转)

    夫妻双码农,北京 or 硅谷,值得吗? http://mp.weixin.qq.com/s?__biz=MzA5MzE4MjgyMw==&mid=401228574&idx=1& ...

  8. 使用批处理(bat)脚本对目录树下同种性质的目录或文件进行处理

    问题起源:每次从svn管理的目录下面复制目录之后里面总是有很多.svn的目录,虽说不影响使用但看着很碍眼.同时自己也懒得使用svn的export功能. 因此一个简单的批处理脚本可以帮助我们搞定一切,当 ...

  9. C#之类与对象

    这段代码告诉我们要把#define DEBUG放在文件的开头位置,不然会导致编译错误,最后还要#endif 以上代码告诉我们可以对自己创建的类设计自己的构造方法,然后可以通过具体的Main()函数来通 ...

  10. python入门基础代码

    #查找index函数的帮助 help(str.index) #for循环和break语句from math import sqrtfor i in range(2,101): flag=1 k=int ...