#include <queue>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include<algorithm>
using namespace std;
int main(){
int num,n;
while(cin>>num>>n){
bool temp=false;
int Array[n];
for(int i = 0 ;i < n;i++){
cin>>Array[i];
}
sort(Array,Array+n);
for(int i = 0; i < n ;i++)
{
if(Array[i]+Array[n-1]<num)
continue;
for(int j = i+1;j < n&&Array[i]+Array[j]<=num;j++)
{
if(Array[i]+Array[j]==num)
{
temp=true;
cout<<Array[i]<<" "<<Array[j]<<endl;
}
}
}
if(!temp)
cout<<"No Solution"<<endl;
}
return 0;
}
51nod 1001
貌似這道題需要用二分 但是我直接暴力也過了 剛開始超時 後來我把標誌變量改成了bool 並且加上了小數據重新循環的限制條件就過了 自己也是挺
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.