UVA 10125 Sumsets

Source: Internet
Author: User

Sumsetstime limit:1000msmemory limit:65536kbthis problem'll be judged onPKU. Original id:2549
64-bit integer IO format: %lld Java class name: Main Iven S, a set of integers, find the largest d such that A + B + c = d where a, B, C, and D is distinct elements of S.InputSeveral S, each consisting of a line containing an integer 1 <= n <=-indicating the number of elements in S, fo Llowed by the elements of S, one per line. Each element of S is a distinct integer between-536870912 and +536870911 inclusive. The last line of input contains 0.OutputFor each S, a single line containing d, or a single line containing "no solution".Sample Input
52 3 5 7 1252 16 64 256 10240
Sample Output
12NO Solution
SourceWaterloo local 2001.06.02 Problem solving: two points.
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 structNode {5 LL Val;6     intx, y;7Node (LL V,intAintb): Val (v), X (a), Y (b) {}8     BOOL operator< (ConstNode &t)Const {9         returnVal <T.val;Ten     } One     BOOL operator> (ConstNode &t)Const { A         returnVal >T.val; -     } -     BOOL operator!=(ConstNode &t)Const { the         returnX! = T.x && Y! = T.y && x! = T.y && Y! =T.x; -     } - }; -Vector<node>b; +LL d[1010]; - intMain () { +Ios::sync_with_stdio (false); A     intN; at      while(Cin>>n &&N) { -          for(inti =0; I < n; ++i) cin>>D[i]; - a.clear (); - b.clear (); -          for(inti =0; I < n; ++i) -              for(intj = i +1; J < N; ++j) { inA.push_back (Node (d[i) +d[j],i,j)); -B.push_back (Node (d[i)-d[j],i,j)); toB.push_back (Node (D[J)-d[i],j,i)); +             } - sort (A.begin (), A.end ()); the sort (B.begin (), B.end ()); * LL ret; $memset (&ret,0x80,sizeof(LL));Panax Notoginseng          for(Auto it = A.begin (); It! = A.end (); + +it) { -Auto Lvalue = Lower_bound (B.begin (), B.end (), *it); theAuto Rvalue = Upper_bound (Lvalue,b.end (), *it); +              for(; Lvalue! = rvalue; + +lvalue) A                 if(*lvalue! = *it) theret = max (Ret,it->val + d[lvalue->y]); +         } -         if(Ret <-536870912) $cout<<"No solution"<<Endl; $         Elsecout<<ret<<Endl; -     } -     return 0; the } - /*Wuyi 5 the 2 - 3 Wu 5 - 7 About  A $ */
View Code

UVA 10125 Sumsets

Contact Us

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.