POJ2549:Sumsets——题解
http://poj.org/problem?id=2549
题目大意:从集合中找到四个不相同的数,满足a+b+c=d,输出最大的d。
——————————————————————————
该式子变为a+b=d-c,于是我们可以通过枚举d-c,查找是否有a+b满足的值。
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=-;
int a[];
int main(){
int n;
while(scanf("%d",&n)!=EOF&&n){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+,a+n+);
bool ok=;
for(int i=n;i>=;i--){
for(int j=n;j>=;j--){
if(i==j)continue;
int k=a[i]-a[j],l=,r=j-;
while(l<r){
if(k<a[l]+a[r]){
r--;
}else if(k>a[l]+a[r]){
l++;
}else{
printf("%d\n",a[i]);
ok=;
break;
}
}
if(ok)break;
}
if(ok)break;
}
if(!ok)printf("no solution\n");
}
return ;
}
POJ2549:Sumsets——题解的更多相关文章
- poj2549 Sumsets
Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11886 Accepted: 3273 Descript ...
- poj 折半搜索
poj2549 Sumsets 题目链接: http://poj.org/problem?id=2549 题意:给你一个含有n(n<=1000)个数的数列,问这个数列中是否存在四个不同的数a,b ...
- 题解报告:hdu 2709 Sumsets
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2709 Problem Description Farmer John commanded his co ...
- BZOJ1677: [Usaco2005 Jan]Sumsets 求和
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 570 Solved: 310[Submi ...
- Sumsets(3sum问题,枚举d,c二分a+b)
Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9997 Accepted: 2736 Descripti ...
- Sumsets(完全背包)
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 15045 Accepted: 5997 Descrip ...
- BZOJ 1677: [Usaco2005 Jan]Sumsets 求和
题目 1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 617 Solved: 344[Su ...
- 1677: [Usaco2005 Jan]Sumsets 求和
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 626 Solved: 348[Submi ...
- Sumsets(数学)
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 14964 Accepted: 5978 Description ...
随机推荐
- DSP5509的中断学习-第4篇
1. 编译工程的时候出现一个问题,如下 specifies large memory model, which is not compatible with small memory 2. 修改工程设 ...
- records_in_range start_key, end_key
select * from federatedTest where name='aaa';(gdb) p *start_key$2 = {key = 0x7f64f4103be8 "&quo ...
- 多台服务器下同步文件夹数据(rsync+inotify)
网上有很多讲解rsync+inotify的教程,我就先贴出一个来大家去看吧,基本都是类似的. http://www.jb51.net/article/57011.htm 我就强调几点,按照上面的方法配 ...
- 「日常训练」Skills(Codeforce Round #339 Div.2 D)
题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做 ...
- 「日常训练」Duff in the Army (Codeforces Round #326 Div.2 E)
题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\ ...
- 「日常训练」School Marks(Codeforces Round 301 Div.2 B)
题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...
- jQuery筛选器及对DOM修改(学习笔记)
1.jQuery筛选器 注意:请先在管理Nuget程序包中查找jQuery包,并安装.也可以在jQuery官网下载. 实现: <!DOCTYPE html> <html xmlns= ...
- linux学习总结----shell编程
## 环境变量 ## 全局变量 ``` 常见的全局环境变量 PATH 指令的搜索路径 HOME 用户的家目录 LOGNAME 登录名 SHELL 脚本的类型 使用全局环境变量 echo $PATH 自 ...
- 解决ssh_exchange_identification:read connection reset by peer 原因
服务器改了密码,试过密码多次后出现: ssh_exchange_identification: read: Connection reset by peer 可以通过ssh -v查看连接时详情 Ope ...
- Windows环境下使用kafka单机模式
测试运行环境 Win10 kafka_2.11-1.0.0 zookeeper-3.4.10 1.安装Zookeeper Kafka的运行依赖于Zookeeper,所以在运行Kafka之前我们需要安装 ...