题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1090

找到所有数的和,然后再原数组里二分找符合条件的第三个数。

 #include <bits/stdc++.h>
using namespace std; const int maxn = ;
const int maxm = maxn * maxn;
typedef struct R {
int x, y, z;
R(){}
R(int x, int y, int z) : x(x), y(y), z(z) {}
bool operator == (R t) {
return x == t.x && y == t.y && z == t.z;
}
}R;
typedef struct S {
int i, j;
int s;
}S; vector<R> ret;
int n, m;
int a[maxn];
S s[maxm]; bool cmp(R a, R b) {
if(a.x == b.x) {
if(a.y == b.y) return a.z < b.z;
return a.y < b.y;
}
return a.x < b.x;
} int main() {
// freopen("in", "r", stdin);
while(~scanf("%d", &n)) {
m = ; ret.clear();
for(int i = ; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a+n);
for(int i = ; i < n; i++) {
for(int j = i+; j < n; j++) {
s[m].i = i; s[m].j = j; s[m].s = a[i] + a[j];
m++;
}
}
for(int i = ; i < m; i++) {
int x = -s[i].s;
int id = lower_bound(a, a+n, x) - a;
if(a[id] == x && id != s[i].i && id != s[i].j) {
int x = a[s[i].i], y = a[s[i].j], z = a[id];
if(x > y) swap(x, y);
if(x > z) swap(x, z);
if(y > z) swap(y, z);
ret.push_back(R(x,y,z));
}
}
if(ret.size() == ) {
puts("No Solution");
continue;
}
sort(ret.begin(), ret.end(), cmp);
ret.erase(unique(ret.begin(), ret.end()), ret.end());
for(int i = ; i < ret.size(); i++) {
printf("%d %d %d\n", ret[i].x, ret[i].y, ret[i].z);
}
}
return ;
}

[51NOD1090] 3个数和为0(水题,二分)的更多相关文章

  1. hdu - 6276,2018CCPC湖南全国邀请赛A题,水题,二分

    题意: 求H的最大值,  H是指存在H篇论文,这H篇被引用的次数都大于等于H次. 思路:题意得,  最多只有N遍论文,所以H的最大值为N, 常识得知H的最小值为0. 所以H的答案在[0,N]之间,二分 ...

  2. UVaLive 3971 Assemble (水题二分+贪心)

    题意:你有b元钱,有n个配件,每个配件有各类,品质因子,价格,要每种买一个,让最差的品质因子尽量大. 析:很简单的一个二分题,二分品质因子即可,每次计算要花的钱的多少,每次尽量买便宜且大的品质因子. ...

  3. ytu 1061: 从三个数中找出最大的数(水题,模板函数练习 + 宏定义练习)

    1061: 从三个数中找出最大的数 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 124[Submit][Status][We ...

  4. SPOJ CNTPRIME 13015 Counting Primes (水题,区间更新,求区间的素数个数)

    题目连接:http://www.spoj.com/problems/CNTPRIME/ #include <iostream> #include <stdio.h> #incl ...

  5. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  8. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  9. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

随机推荐

  1. Openstack的mysql数据多主galera的错误

    登录openstack的在dashboard,提示说权限验证错误,有2种情况: 1. 密码被人改了. 2. 系统发生了问题. 密码确认没人改,所以查看/var/log/keystone-all.log ...

  2. Angularjs之controller 和filter(四)

    Controller组件(http://www.angularjs.cn/A00C) 在AngularJS中,控制器是一个Javascript函数(类型/类),用来增强除了根作用域以外的作用域实例的. ...

  3. 一小时学会Markdown写作

    写作也是创作一件产品.以易懂.简洁.凝练的方式表达观点.阐述见解和知识,发挥影响力. 为什么要使用 Markdown 博文迁移的排版兼容.当在多个博客之间,或者在线博客与本地笔记软件之间迁移的时候,排 ...

  4. linux设备驱动归纳总结(一)内核的相关基础概念【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-59413.html linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxx ...

  5. 【python cookbook】【字符串与文本】13.对齐文本字符串

    问题:以某种对齐方式将文本做格式化处理 解决方案: 1.针对字符串:ljust().rjust().center()方法 2.针对任何值,更加通用的:format()  更多内容:https://do ...

  6. awr报告生成方法

    以上是在linux的oracle的命令截图. 如果是在unix的命令,则需要在命令前面加上\符号,变成了\@$ORACLE_HOME/rdbms/admin/awrrpt.sql

  7. 在CentOS之上搭建VMware Player 7

    1.下载VMware-Player-7.1.2安装包 百度网盘下载地址: 链接:http://pan.baidu.com/s/1nudfo6H 密码:oemc 直接下载地址: https://down ...

  8. php的header()函数之设置content-type

    //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Content-type: application/at ...

  9. 20145227 《Java程序设计》实验四实验报告

    20145227 <Java程序设计>实验四实验报告 实验内容 安装Andriod Studio并配置软件 使用Andriod Studio软件实现Hello World的小程序 实验步骤 ...

  10. POJ 2406:Power Strings

    Power Strings Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 41252   Accepted: 17152 D ...