codeforces-2549【枚举】【特殊的二分】
来源:互联网 发布:opencv实现算法 编辑:程序博客网 时间:2024/05/17 21:38
题目链接:点击打开链接
Sumsets
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11104 Accepted: 3036
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
题意:在集合 S 中有 n 个数,找到最大的 d,且 d 满足于集合内 a+b+c=d。
思路:注意一下是集合,所以 a,b,c,d 均不能相同
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int MAXN=1e6+10;int n;int a[1010];bool judge(int l,int r,int x) // 特殊的二分 {while(l<r){if(x<a[l]+a[r])r--;else if(x>a[l]+a[r])l++;elsereturn 1;}return 0;}int main(){while(scanf("%d",&n),n){for(int i=0;i<n;i++)scanf("%d",a+i);sort(a,a+n);bool flag=0;for(int i=n-1;i>=0;i--){for(int j=n-1;j>=0;j--){if(i==j)continue;if(judge(0,j-1,a[i]-a[j])){printf("%d\n",a[i]);flag=1;break;}}if(flag)break;}if(!flag)puts("no solution");}return 0; }
0 0
- codeforces-2549【枚举】【特殊的二分】
- codeforces 734 C 二分+枚举
- Codeforces 496D Tennis Game 枚举+二分
- Codeforces 493C 枚举加二分
- Codeforces 651D Image Preview【二分+枚举】
- Codeforces 799C Fountains 枚举+二分
- 二分优化的暴力枚举
- poj 2549 Sumsets (枚举+二分)
- Codeforces 488C Fight the Monster【二分+枚举】
- Codeforces-734C-Anton and Making Potions(枚举+二分)
- Codeforces 496D Tennis Game【连续二分+枚举】
- 水滴石穿_java枚举的特殊用法
- 浅谈特殊枚举思想的应用
- 亚波利纳里斯的魔法糕点 二分枚举
- 二分--CodeForces
- 枚举之特殊密码锁
- 蓝桥杯-基础训练-特殊的回文数(枚举)
- codeforces 183(div2) A. Pythagorean Theorem II 枚举+二分查找
- 像是突然打通任督二脉
- 浅谈Html的内容加载及JS执行顺序
- matlab傅里叶变换矩阵
- JavaScript基础之【初做一个选项卡】
- 《教父》影评
- codeforces-2549【枚举】【特殊的二分】
- HTML5 <script>异步属性async
- LeetCode 155 Min Stack
- Dubbo 接口 、提供者、消费者
- 如何创建签名证书
- 从USB驱动器运行Windows 10
- 北航计算机机试15相亲数
- 2017.03.10【NOIP 普及组】模拟赛C组 岛屿Islands 题解
- CSU OJ 1803 2016 数论题? 机智题。。