Skip to content

Commit 8f95c2b

Browse files
committed
add
1 parent f3a743e commit 8f95c2b

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

9.5

0 Bytes
Binary file not shown.

9.5.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using namespace std;
33

44
int search(string s[], int low, int high, string x){
5+
if(x == "") return -1;
56
while(low <= high){
67
int mid = (low+high)>>1;
78
int t = mid;
@@ -10,7 +11,7 @@ int search(string s[], int low, int high, string x){
1011
else{
1112
if(s[t] == x) return t;
1213
else if(s[t] < x) low = t + 1;
13-
else high = t - 1;
14+
else high = mid - 1; //or t-1, (mid, t)为空字符串
1415
}
1516
}
1617
return -1;

9.7

124 Bytes
Binary file not shown.

9.7.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
using namespace std;
55

66
const int maxn = 100;
7-
struct point{
7+
struct person{
88
int h, w;
99
};
10-
point p[maxn];
10+
person p[maxn];
1111
int d[maxn];
1212

13-
bool cmp(point p1, point p2){
13+
bool cmp(person p1, person p2){
1414
if(p1.h == p2.h) return p1.w < p2.w;
1515
else return p1.h < p2.h;
1616
}
17-
int lis(point p[], int n){
17+
int lis(person p[], int n){
1818
int k = 1;
1919
d[0] = p[0].w;
2020
for(int i=1; i<n; ++i){
2121
if(p[i].w >= d[k-1]) d[k++] = p[i].w;
2222
else{
2323
int j;
24-
for(j=k-1; j>=0 && d[j]>p[i].w; --j);
24+
for(j=k-1; j>=0 && d[j]>p[i].w; --j);//用二分可将复杂度降到O(nlogn)
2525
d[j+1] = p[i].w;
2626
}
2727
}

0 commit comments

Comments
 (0)