51Nod 1090 3个数之和
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-1,l=0,m; while(l<=r){ m=(l+r)/2; if(x==arr[m]) return m; else if(x>arr[m]) l=m+1; else r=m-1; } return -1; } int main() { int n,t,m; while(~scanf("%d",&n)){ for(int i=0;i<n;i++){ scanf("%d",&arr[i]); } sort(arr,arr+n); int k,c=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ k=Find(n,-arr[i]-arr[j]); if(k!=-1){ 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 0; }