poj 2549 Sumsets
来源:互联网 发布:淘宝越刷排名越靠后 编辑:程序博客网 时间:2024/06/06 19:35
Description
Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S.
Input
Several S, each consisting of a line containing an integer 1 <= n <= 1000 indicating the number of elements in S, followed 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.
Output
For 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
Source
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<string>using namespace std;int s[1010];int main(){ int n; while(~scanf("%d",&n)&&n) { int ans; bool flag=true; for(int i=0; i<n; i++) scanf("%d",&s[i]); sort(s,s+n); int nn=unique(s,s+n)-s; n=nn; for(int i=n-1; i>=0; i--) { for(int j=0; j<n-1; j++) { int head=j+1,tail=n-1; while(head<tail) { int mm=s[j]+s[head]+s[tail]; if(mm==s[i]) { if(i==j||i==head||i==tail) break; ans=mm; flag=false; break; } else if(mm>s[i]) tail--; else head++; } if(flag==false) break; } if(flag==false) break; } if(flag==0) printf("%d\n",ans); else printf("no solution\n"); } return 0;}
0 0
- poj 2549 Sumsets
- poj 2549 Sumsets
- POJ 2549 Sumsets
- POJ-2549-Sumsets
- poj 2549 Sumsets
- poj 2549 Sumsets
- poj 2549 Sumsets(hash)
- POJ 2549 Sumsets
- POJ 2549:Sumsets
- poj 2549 Sumsets
- POJ 2549 Sumsets hash
- poj 2549 Sumsets
- poj 2549 Sumsets
- POJ-----2549---Sumsets---二分
- Poj 2549/Hoj 1879 Sumsets
- UVa 10125 & POJ 2549 - Sumsets
- POJ 2549 Sumsets(折半枚举)
- poj--2549--Sumsets(二分)
- Android之Activity(二)生命周期
- 前端和后端是如何交互的
- Win10 64bit安装VC6+VC6助手
- 布局
- 15. 3Sum,16. 3Sum Closest,18. 4Sum(最后一个方法重要)重要
- poj 2549 Sumsets
- 拦截导弹
- SAS 关联规则
- CF
- form表单中的lable标签
- Internet Explorer(CVE-2012-1889)暴雷漏洞分析报告【WinXP&IE8版】
- 解决Cannot change version of project facet Dynamic web module to 3.0
- Linux
- 排序算法优劣