我看到这个的第一反应就是爆搜,然后写了一个没加$No$的4分程序
#include <bits/stdc++.h> #include <algorithm> #define it int #define fr for #define il inline using namespace std; it book[100020],t[100020]; it spe[50010]; it n,m,bz=0; it main(); it find(); it max(); it min(); il it min(it a,it b){if(a>b){return b;}else{return a;} } il it max(it a,it b){if(a>b){return a;}else{return b;} } void print(it cho,it now){if(bz==0){ printf("%d %d",t[cho],t[now]);bz=1; } return ; } it find(it cho,it now){it j=0; book[cho]=1;if(t[cho]+t[now]==m){print(cho,now);return 0;}fr(it i=1;i<=n;i++){if(book[i]==0){book[i]=1;find(cho,i);book[i]=0;}}return 0; } it main(){scanf("%d",&n);fr(it i=1;i<=n;i++){book[i]=0;scanf("%d",&t[i]);}sort(t+1,t+1+n);scanf("%d",&m);fr(it i=1;i<=n;i++){find(i,0);if(bz==1){return 0;}}return 0; }
然而很快发现自己没加$No$,于是机智地补上了
#include <bits/stdc++.h> #include <algorithm> #define it int #define fr for #define il inline using namespace std; it book[100020],t[100020]; it spe[50010]; it n,m,bz=0; it main(); it find(); it max(); it min(); il it min(it a,it b){if(a>b){return b;}else{return a;} } il it max(it a,it b){if(a>b){return a;}else{return b;} } void print(it cho,it now){if(bz==0){ printf("%d %d",t[cho],t[now]);bz=1; } return ; } it find(it cho,it now){it j=0; book[cho]=1;if(t[cho]+t[now]==m){print(cho,now);return 0;}fr(it i=1;i<=n;i++){if(book[i]==0){book[i]=1;find(cho,i);book[i]=0;}}return 0; } it main(){scanf("%d",&n);fr(it i=1;i<=n;i++){book[i]=0;scanf("%d",&t[i]);}sort(t+1,t+1+n);scanf("%d",&m);fr(it i=1;i<=n;i++){find(i,0);if(bz==1){return 0;}}if(bz==0){printf("No");}return 0; }
$mmp$怎么还是只有6分........................................................................
这时我看到了这个练习的标题
$1.11$编程基础之二分查找
mmp
然后就出来了...
代码补充中~~~~~