HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9

/*
HDU 6168 - Numbers [ 思维 ]  |  2017 ZJUT Multi-University Training 9
题意:
	....
分析:
	全放入multiset 从小到大,慢慢筛
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 125250;
int n, s[N];
int a[N], cnt;
multiset<int> st;
multiset<int>::iterator it, pos;
int main()
{
    int x;
    while (~scanf("%d", &n))
    {
        st.clear();
        for (int i = 1; i <= n; ++i)
        {
            scanf("%d", &x);
            st.insert(x);
        }
        cnt = 0;
        for (it = st.begin(); it != st.end(); it++)
        {
            a[++cnt] = *it;
            for (int i = 1; i < cnt; i++)
            {
                pos = st.find(a[i]+a[cnt]);
                st.erase(pos);
            }
        }
        printf("%d\n", cnt);
        for (int i = 1; i < cnt; i++) printf("%d ", a[i]);
        if (cnt) printf("%d\n", a[cnt]);
    }
}

  

时间: 2024-10-17 13:06:55

HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9的相关文章

hdu 6168 Numbers

题解:和前面的多校的一道题目类似,顺序遍历的时候,a元素是比b要小的.用求出来的a去筛一遍b就可以了. #include <iostream> #include <vector> #include <map> #include <cstdio> using namespace std; vector<int>ans; int c[130000]; int main() { int m; while(~scanf("%d",&a

HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9

/* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问两串是否匹配 分析: dp[i][j] 代表B[i] 到 A[j]全部匹配 然后根据三种匹配类型分类讨论,可以从i推到i+1 复杂度O(n^2) */ #include <bits/stdc++.h> using namespace std; const int N = 2505; int t;

hdu 5802 Windows 10(2016 Multi-University Training Contest 6——贪心+dfs)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5802 Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1005    Accepted Submission(s): 333 Problem Description Long long ago, there was a

洛谷P2723 丑数 Humble Numbers [2017年 6月计划 数论07]

P2723 丑数 Humble Numbers 题目背景 对于一给定的素数集合 S = {p1, p2, ..., pK},考虑一个正整数集合,该集合中任一元素的质因数全部属于S.这个正整数集合包括,p1.p1*p2.p1*p1.p1*p2*p3...(还有其 它).该集合被称为S集合的“丑数集合”.注意:我们认为1不是一个丑数. 题目描述 你的工作是对于输入的集合S去寻找“丑数集合”中的第N个“丑数”.所有答案可以用longint(32位整数)存储. 补充:丑数集合中每个数从小到大排列,每个丑

hdu 5775 Bubble Sort(2016 Multi-University Training Contest 4——树状数组)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5775 Bubble Sort Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 636    Accepted Submission(s): 378 Problem Description P is a permutation of the

HDU Humble Numbers (dp)

Humble Numbers Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 8   Accepted Submission(s) : 4 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description A number whose only prim

(最小费用流)hdu 6118(2017百度之星初赛B 1005) 度度熊的交易计划

度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 260    Accepted Submission(s): 83 Problem Description 度度熊参与了喵哈哈村的商业大会,但是这次商业大会遇到了一个难题: 喵哈哈村以及周围的村庄可以看做是一共由n个片区,m条公路组成的地区. 由于生产能力的区别,第i个片

HDU多校2017第7场

6121 Build a tree 6125 Free from square 6126 Give out candies 6127 Hard challenge 6128 Inverse of sum 6129 Just do it 对于变换$m$次之后的序列,考虑$a_0$对$a_i(0 \le i < n)$的贡献,为$C_{m-1+i}^i$个$a_0$相异或的结果.同样地,$a_1$对$a_{i+1}(0 \le i<n-1)$的贡献也为$C_{m-1+i}^i$.然后,组合数判定奇

hdu 5181 numbers——思路+区间DP

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.html 原来卡特兰数的这个问题还能区间DP…… XO #include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std; int rdn() { in