Brush question--hdu 6168 Numbers

Source: Internet
Author: User
Tags printf sort
/*
Put the AB array into the map record and sort the AB array
AB[0],AB[1] must be A1,A2 (no doubt)
Next do not know is A1+A2, or A3, in the map will a1+a2 remove 1
The AB sequence is found in the map, the first number is not 0 is A3 (A1,A2,A1+A2) has been removed 1
In the same way, A1+A3,A2+A3 is removed from the number of the number not 0 is A3
In turn, the A array is calculated
*/
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace Std;
int ab[125300];
int a[125300];
int n,m,l;
int main () {
while (~SCANF ("%d", &m)) {
n= (int) sqrt (m*2*1.0);
map<int,int>s;
for (int i=0;i<m;i++) {
scanf ("%d", &ab[i]);
s[ab[i]]++;
}
Sort (ab,ab+m);//Do not sort also a
l=0;
for (int i=0;i<m;i++) {
if (s[ab[i]]>0) {
for (int j=0;j<l;j++) {
s[ab[i]+a[j]]--;
}
A[l++]=ab[i];
s[ab[i]]--;
if (l==n) break;
}
}
printf ("%d\n", N);
for (int i=0;i<n;i++) {
if (i) printf ("");
printf ("%d", a[i]);
}
printf ("\ n");
}
return 0;
}
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.