-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHDU-dx2012-5-1003.cpp
156 lines (142 loc) · 2.53 KB
/
HDU-dx2012-5-1003.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
ID: mfs6174
email: [email protected]
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<cmath>
#include<set>
#define sf scanf
#define pf printf
#define llg long long
using namespace std;
//ifstream inf("ti.in");
//ofstream ouf("ti.out");
const int maxlongint=2147483647;
int i,j,k,t,n,m;
const double INF=1e200;
const double Ling=1e-9;
bool fail;
inline int cwz(double x)
{
if (abs(x)<Ling)
return 0;
else
return (x>0)?1:-1;
}
struct P
{
double x;
double y;
//constructor
P(double a=0, double b=0)
{ x=a; y=b;}
P operator+(const P &b) const
{
return P(x + b.x, y + b.y);
}
P operator - (const P &b) const
{
return P(x - b.x, y - b.y);
}
bool operator<(const P &b) const//a在b逆时针
{
return x * b.y < y * b.x;
}
bool operator==(const P &b) const
{
return ((cwz(x-b.x)==0)&&(cwz(y-b.y)==0));
}
double operator ^ (const P &b) const //aXb
{
return x*b.y-b.x*y;
}
double operator *(const P &b) const
{
return x*b.x+y*b.y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
};
struct G
{
P d;
int t,v;
};
inline double dst(P p1,P p2)
{
return( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) );
}
inline bool cmp(const G &a, const G &b)
{ //中心极角排序 从-PI到-PI内
double aa=atan2(a.d.y, a.d.x),bb=atan2(b.d.y, b.d.x);
if (cwz(aa-bb)==0)
return a.d.y<b.d.y;
else
return aa > bb;
}
G dian[500];
int f[50000];
int dui[300],dai[300];
int nn,v,zz;
int main()
{
freopen("ti.in","r",stdin);
while (sf("%d%d",&n,&m)!=EOF)
{
zz++;
for (i=1;i<=n;i++)
{
dian[i].d.input();
sf("%d%d",&dian[i].t,&dian[i].v);
}
sort(&dian[1],&dian[n+1],cmp);
memset(f,0,sizeof(f));
double tt=-6;
for (i=1,nn=0;i<=n;i++)
{
if ( cwz(atan2(dian[i].d.y,dian[i].d.x)-tt)!=0)
{
nn++;
dui[nn]=i;
dai[nn]=1;
}
else
{
dai[nn]++;
}
tt=atan2(dian[i].d.y,dian[i].d.x);
}
for (i=1;i<=nn;i++)
for (k=m;k>=0;k--)
{
v=t=0;
for(j=1;j<=dai[i];j++)
{
v+=dian[dui[i]+j-1].v;
t+=dian[dui[i]+j-1].t;
if (k-t<0)
break;
f[k]=max(f[k],f[k-t]+v);
}
}
int mm=0;
for (i=0;i<=m;i++)
mm=max(mm,f[i]);
printf("Case %d: %d\n",zz,mm);
}
return 0;
}