POJ2549-Sumsets
来源:互联网 发布:彩票计划软件源码 编辑:程序博客网 时间:2024/05/16 17:46
这道题可以将a+b+c=d改为a+b=d-c,然后折半枚举d-c的所有可能性,然后找出是否存在a+b满足条件即可。
#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1000 + 5;int s[maxn];int main(int argc, char const *argv[]) { int n; while (scanf("%d", &n) == 1 && n) { for (int i = 0; i < n; i++) { scanf("%d", &s[i]); } sort(s, s + n); int ans; bool find = false; for (int i = n - 1; i >= 0; i--) { for (int j = n - 1; j >= 0; j--) { if (i == j) { continue; } int sum = s[i] - s[j]; int l = 0, u = j - 1; while (l < u) { int acl = s[l] + s[u]; if (acl == sum) { find = true; ans = s[i]; break; } else if (acl > sum) { u--; } else { l++; } } if (find) { break; } } if (find) { break; } } if (find) { printf("%d\n", ans); } else { puts("no solution"); } } return 0;}
0 0
- poj2549 Sumsets
- POJ2549-Sumsets
- POJ2549-Sumsets
- POJ2549-Sumsets
- poj2549——Sumsets
- POJ2549 Sumsets 折半枚举
- poj2549 Sumsets(折半枚举)
- POJ2549-Sumsets【折半搜索】
- poj2549 Sumsets双向搜索
- poj2549 Sumsets(中途相遇法)
- Uva10125/POJ2549——Sumsets(中途相遇法,hash)
- poj2549
- poj2549
- poj2549
- Sumsets
- Sumsets
- Sumsets
- Sumsets
- 【61】序列化二叉树
- POJ 2635 The Embarrassed Cryptographer
- 存个图片。。。
- UIViewController的几种跳转模式及其应用
- UML图学习之二 类图
- POJ2549-Sumsets
- C++之string类型详解
- UML图学习之三 状态图
- UML图学习之四 活动图
- UVALive 7278 Game of Cards
- AVL树详解(附c++代码)
- UML图学习之五 序列图(顺序图)和协作图
- Android开发bug日记
- AE、IDL开发问题锦集