HDU 6168 Numbers 思维 水题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6168
题目描述: 定义数组b是由数组a每两项的和组成的,现在将数组A, B混在一起给你, 筛出数组A
解题思路: 这题其实很简单的........之前脑子短路了, 以为记录两个数加和的次数是原来m中的和会超时就没那么做.....是真的蠢, 打实时比赛的时候思路不够清晰啊, 其实只要记录一下每个和就可以了....
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iterator> #include <cmath> #include <algorithm> #include <stack> #include <deque> #include <map> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define mem0(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,-0x3f,sizeof(a)) #define fi(n) for(i=0;i<n;i++) #define fj(m) for(j=0;j<m;j++) #define sca(x) scanf("%d",&x) #define scalld(x) scanf("%I64d",&x) #define print(x) printf("%d\n", x) #define printlld(x) printf("%I64d\n",x) #define de printf("=======\n") #define yes printf("YES\n") #define no printf("NO\n") typedef long long ll; using namespace std; const int maxm = 125260; int a[maxm]; int ans[maxm]; map<int, int> MAP; int main() { int m; while( sca(m) == 1 ) { mem0(a); mem0(ans); MAP.clear(); for( int i = 1; i <= m; i++ ) { sca( a[i] ); } sort( a+1, a+m+1 ); ans[1] = a[1]; int pos = 2; for( int i = 2; i <= m; i++ ) { if( MAP[a[i]] == 0 ) { ans[pos] = a[i]; for( int j = 1; j < pos; j++ ) { MAP[ans[pos]+ans[j]]++; } pos++; } else { MAP[a[i]]--; } } printf( "%d\n", pos-1 ); for( int i = 1; i < pos; i++ ) { if( i == 1 ) printf( "%d", ans[i] ); else printf( " %d", ans[i] ); } printf( "\n" ); } return 0; }
思考: 我是真的菜........是真的菜......vegetable
posted on 2017-08-22 17:33 FriskyPuppy 阅读(139) 评论(0) 编辑 收藏 举报