杭电hdu-6168 Numbers

这一题是考察排序与后续数据处理的题。我是用了map来给“和”做标记,把确定为a数组内数的数两两求和。给这些和标记,这样就可以很好的处理带有重复数的数据了~~

贴个碼:

#include<iostream>
#include<map>
#include<stdio.h>
#include<algorithm>
using namespace std;
map<int,int> mp;
int a[550],i,j,k,e=0,b[126000];
int main()
{
	int n,m;
	while(scanf("%d",&n)!=EOF)
	{
		e=0;
		for(i=0;i<n;i++) scanf("%d",&b[i]);
		sort(b,b+n);
		mp.clear();
		for(i=0;i<n;i++)
		{
			if(mp[b[i]])
			{
				mp[b[i]]--;
				continue;
			}
			for(j=0;j<e;j++)
			{
				mp[a[j]+b[i]]++;
			}
			a[e++]=b[i];
		}
		cout<<e<<endl;
		for(i=0;i<e;i++) 
		{
			cout<<a[i];	
			if(i!=e-1) cout<<" ";
			else cout<<endl;
		}
	}
}
 

 

  这样就ojbk了

 

posted @ 2017-10-08 15:11  啾啾猫猫  阅读(117)  评论(0编辑  收藏  举报