Input示例
7
-3
-2
-1
0
1
2
3
Output示例
-3 0 3
-3 1 2
-2 -1 3
-2 0 2
-1 0 1
#include "bits/stdc++.h"
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f3f
#define PI acos(-1)
#define N 1010
#define MOD 10
using namespace std;
int arr[N];
int Find(int n,int x){
int r=n-,l=,m;
while(l<=r){
m=(l+r)/;
if(x==arr[m])
return m;
else if(x>arr[m])
l=m+;
else
r=m-;
}
return -;
}
int main()
{
int n,t,m;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d",&arr[i]);
}
sort(arr,arr+n);
int k,c=;
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
k=Find(n,-arr[i]-arr[j]);
if(k!=-){
if(k<=j||k<=i)
break;
printf("%d %d %d\n",arr[i],arr[j],-arr[i]-arr[j]);
c++;
}
}
}
if(!c){
puts("No Solution");
}
}
return ;
}

51Nod 1090 3个数之和的更多相关文章

  1. 51Nod 1090 3个数和为0(暴力)

    1090 3个数和为0 基准时间限制:1 秒 空间限制:131072 KB 分值: 5         难度:1级算法题 给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等.从 ...

  2. 51nod 1090 3个数和为0【二分】

    1090 3个数和为0 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等.从 ...

  3. 51Nod 1090 3个数和为0

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1090 思路:排序 三个for循环 但是要控制循环 不能从头开 ...

  4. 51Nod 1090 3个数和为0 set 二分优化

    给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等.从中找出所有和 = 0的3个数的组合.如果没有这样的组合,输出No Solution.如果有多个,按照3个数中最小的数从小到 ...

  5. [51nod] 1090 3个数和为0 暴力+二分

    给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等.从中找出所有和 = 0的3个数的组合.如果没有这样的组合,输出No Solution.如果有多个,按照3个数中最小的数从小到 ...

  6. 51Nod 1090: 3个数和为0

    1090 3个数和为0  基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等. ...

  7. 51nod 1040 最大公约数之和(欧拉函数)

    1040 最大公约数之和 题目来源: rihkddd 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题   给出一个n,求1-n这n个数,同n的最大公约数的和.比如: ...

  8. 51nod 1244 莫比乌斯函数之和 【杜教筛】

    51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...

  9. 51nod 1244 莫比乌斯函数之和

    题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积 ...

随机推荐

  1. Bower 显示‘bower ESUDO Cannot be run with sudo’的错误解决方法

    使用 sudo 命令后或者当前用户为 root,执行 bower 相关命令会出现错误: 解决办法: 在命令后面加 --allow-root 例: bower init  --allow-root bo ...

  2. iOS-加载html字符串

    NSMutableAttributedString * attrString =[[NSMutableAttributedString alloc] initWithData:[resultModel ...

  3. <Android>菜单资源的使用

    典型菜单资源结构:<menu>根元素且没有属性,在<menu>根元素里面会嵌套<item>和<group>子元素,<item>里面可以嵌套& ...

  4. 在 Range 对象中,Min (14)必须小于或等于 max (-1)。

    DataTable dt = ds.Tables[]; DataRow[] drs = dt.Select("Id=" + categoryID ); 解决方法:将参数用单引号阔起 ...

  5. PAT 1052 卖个萌

    https://pintia.cn/problem-sets/994805260223102976/problems/994805273883951104 萌萌哒表情符号通常由“手”.“眼”.“口”三 ...

  6. sublime Text3 如何自动排版代码

    安装 html beautiful 然后按ctrl+shift+alt+f

  7. 在c++中调用exe程序进行操作

    #include <Windows.h> #include <iostream> #include <direct.h> #define picNum 228 us ...

  8. WPF DataGrid的使用

    构造数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...

  9. 【bzoj1038】瞭望塔 半平面交

    题目描述 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线(x1, y1), ( ...

  10. 【bzoj1634】[Usaco2007 Jan]Protecting the Flowers 护花 贪心

    题目描述 Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the grass, a ...