Bestcoder Round8

4989Summary

既然用C++了就偷懒直接用STL大法了

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int n;
    while (cin >> n)
    {
        vector<long long> vec,temp;
        long long a;
        //读取数据
        while (n--){
            cin >> a;
            temp.push_back(a);
        }
        //计算加法,压入vec中
        int i, j;
        for (i = 0; i < (int)temp.size() - 1;i++)
        for (j = i + 1; j < (int)temp.size(); j++)
            vec.push_back(temp[i] + temp[j]);
        //排序,去重
        sort(vec.begin(), vec.end());
        vector<long long>::iterator ite_end;
        ite_end = unique(vec.begin(), vec.end());
        vec.erase(ite_end, vec.end());
        //遍历求和
        long long sum=0;
        vector<long long>::iterator ite;
        for (ite = vec.begin(); ite != vec.end(); ite++)
            sum += *ite;
        cout << sum << endl;
    }
    return 0;
}
时间: 2024-12-10 06:40:46

Bestcoder Round8的相关文章

BestCoder Round #91

传送门:http://acm.hdu.edu.cn/search.php?field=problem&key=BestCoder+Round+%2391&source=1&searchmode=source A题:给你n种字母,每种字母有个权值vali,共cnti个,现在让你在里面挑出任意数量的字符,组合成一个字符串,该字符串的权值的计算方式为val1*1+val2*2+--+valn*n,让你输出字符串最大的权值是多少.这题很容易会有一个错误的贪心,就是把val为负的舍去,然后v

7-16 Bestcoder a Oracle

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 325    Accepted Submission(s): 139 Problem Description There is once a king and queen, rulers of an unnamed city, who have three daughters of co

HDU 5682/BestCoder Round #83 1003 zxa and leaf 二分+树

zxa and leaf Problem Description zxa have an unrooted tree with n nodes, including (n−1) undirected edges, whose nodes are numbered from 1 to n. The degree of each node is defined as the number of the edges connected to it, and each node whose degree

BestCoder Round #65 (ZYB&#39;s Game)

ZYB's Game Accepts: 672 Submissions: 1207 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description ZYBZYBZYB played a game named NumberBombNumber BombNumberBomb with his classmates in hiking:a host keeps a

BestCoder 1st Anniversary

problem 1001 Souvenir Accepts: 901 Submissions: 2743 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每个参赛者准备一个纪念品. 商店里纪念品的单价是p元, 同时也可以花q元购买纪念品套装, 一个套装里有mm个纪念品. 今天总共有nn个参赛者, Soda想

hdu5418 BestCoder Round #52 (div.2) Victor and World ( floyd+状压dp)

Problem Description After trying hard for many years, Victor has finally received a pilot license. To have a celebration, he intends to buy himself an airplane and fly around the world. There are n countries on the earth, which are numbered from 1 to

【BestCoder】【Round#42】

模拟+链表+DP Orz AK爷faebdc A Growin要跟全部的n个人握手共2n杯香槟,再加上每对关系的两杯香槟,直接统计邻接矩阵中1的个数,再加2n就是answer 1 //BestCoder 42 A 2 #include<vector> 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 #include<iostream> 7 #include<algor

bestcoder#37_1001 字符串,贪心

bestcoder#37_1001 字符串,dfs Rikka with string Accepts: 395 Submissions: 2281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation,

【BestCoder】#29 C GTY&#39;s gay friends(区间和 随机数判重)

题目大意:可以到相应的场次查看中文翻译. 思路:其实这道题很简单,对于一个等差数列,我们要判断他是否每个数都出现,只需要判断区间和或者是最大值是否符合即可,但这边需要注意的便是中间的重复部分.最大值的判重必要性我就不知道了,而且我也不会做,目测做也超时. 这边就写一下偷别人的区间和+随机数判重的做法 其实这边判重的方法是给一个数加上一个超过1000007的权,然后在计算和的时候,便是唯一的. 否则例如下面的情况 10 11的和可以由5和16构成,既然两个的和可以被另外一个的两个数替代,那我们就找