NWERC 2012 Problem J Joint Venture
刚刚开始想的是用二分的方法做,没想到这个题目这么水,直接暴力就行;
代码:
1 #include<cstdio> 2 #include<algorithm> 3 #define maxn 1000005 4 using namespace std; 5 int num[maxn]; 6 7 int main() 8 { 9 int x,n,y,ma; 10 while(scanf("%d",&x)!=EOF) 11 { 12 ma=x*10000000; 13 scanf("%d",&n); 14 for(int i=0;i<n;i++) 15 scanf("%d",&num[i]); 16 sort(num,num+n); 17 x=0,y=n-1; 18 bool flag=0; 19 while(x<y) 20 { 21 if(num[x]+num[y]>ma)y--; 22 else if(num[x]+num[y]<ma)x++; 23 else {flag=1;break;} 24 } 25 if(flag==1)printf("yes %d %d\n",num[x],num[y]); 26 else puts("danger"); 27 } 28 return 0; 29 }