-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1065.cpp
More file actions
109 lines (106 loc) · 1.53 KB
/
1065.cpp
File metadata and controls
109 lines (106 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include<iostream>
using namespace std;
typedef struct{
int lenth;
int weight;
}Stick_t;
int loc(int *a,int sidx,int eidx,int num)
{
int idx;
if(sidx>eidx)
{
return -1;
}
idx=(sidx+eidx)/2;
if(num>=a[idx])
{
if(0==idx)
{
return idx;
}
else if(num<a[idx-1])
{
return idx;
}
else
{
return loc(a,sidx,idx-1,num);
}
}
else
{
return loc(a,idx+1,eidx,num);
}
}
int cmp(void const *a, void const *b)
{
if((*((Stick_t *)a)).lenth==(*((Stick_t *)b)).lenth)
{
return (*((Stick_t *)a)).weight-(*((Stick_t *)b)).weight;
}
else
{
return (*((Stick_t *)a)).lenth-(*((Stick_t *)b)).lenth;
}
}
int main()
{
int i;
int idx;
int testcnt;
int stickcnt;
Stick_t stick[5000];
int val[5000]={0};
int valcnt;
cin>>testcnt;
while(testcnt--)
{
cin>>stickcnt;
memset(val,0,5000);
valcnt=0;
for(i=0;i<stickcnt;i++)
{
cin>>stick[i].lenth>>stick[i].weight;
}
qsort(stick,stickcnt,sizeof(Stick_t),cmp);
for(i=0;i<stickcnt;i++)
{
idx=loc(val,0,valcnt-1,stick[i].weight);
if(-1 == idx)
{
val[valcnt]=stick[i].weight;
valcnt++;
}
else
{
val[idx]=stick[i].weight;
}
}
cout<<valcnt<<endl;
}
#if 0
stickcnt=5000;
for(i=0;i<stickcnt;i++)
{
stick[i].lenth=5000-i;
stick[i].weight=i+1;
}
qsort(stick,stickcnt,sizeof(Stick_t),cmp);
valcnt=0;
for(i=0;i<stickcnt;i++)
{
idx=loc(val,0,valcnt-1,stick[i].weight);
if(-1 == idx)
{
val[valcnt]=stick[i].weight;
valcnt++;
}
else
{
val[idx]=stick[i].weight;
}
}
cout<<valcnt<<endl;
#endif
return 0;
}