bzoj [Usaco2009 Hol]Cattle Bruisers 杀手游戏
生活随笔
收集整理的這篇文章主要介紹了
bzoj [Usaco2009 Hol]Cattle Bruisers 杀手游戏
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Description
?
Input
?第1行輸入N,R,BX,BY,?BVX,BVY,之后N行每行輸入四個(gè)整數(shù)Xi,Yi,VXi,VYi.
?
Output
?
????一個(gè)整數(shù),表示在逃脫過(guò)程中,某一個(gè)時(shí)刻最多有這個(gè)數(shù)理的殺手可以射殺貝茜.
Sample Input
3 1 0 0 0 20 -3 0 4
1 2 -1 1
1 -2 2 -1
Sample Output
2OUTPUT DETAILS:
At time 1.5, Bessie is at point (0, 3), and the three bruisers are
at points (0, 3), (-0.5, 3.5), and (4, -3.5). The first two cattle
bruisers are within 1 unit of Bessie, while the third will never
be within 1 unit of Bessie, so 2 is the most achievable. 思路:? 我們可以計(jì)算出每個(gè)殺手可以射擊的一個(gè)時(shí)間范圍,然后做掃描線。時(shí)間復(fù)雜度$O(nlogn)$ 1 #include<bits/stdc++.h> 2 using namespace std; 3 int const N = 50000 + 3; 4 double const eps = 1e-8; 5 int n, r, m, in[N], out[N], cnt; 6 double bx, by, bvx, bvy, x[N], y[N], vx[N], vy[N], t1[N], t2[N], t[N << 2]; 7 void calc(int k) { 8 double tx = x[k] - bx; 9 double ty = y[k] - by; 10 double v1 = vx[k] - bvx; 11 double v2 = vy[k] - bvy; 12 double a = v1 * v1 + v2 * v2; 13 double b = 2 * v1 * tx + 2 * v2 * ty; 14 double c = tx * tx + ty * ty - 1.0*r * r; 15 double d = b * b - 4 * a * c; 16 if(fabs(a) < eps ) { 17 if( c<0) { // 這個(gè)我始終覺(jué)得很奇怪,為什么c小于0就無(wú)限解了。 18 m++; 19 t1[m] = 0; 20 t2[m] = 1e10; 21 } 22 return ; 23 } 24 if(d<0) return ; 25 t1[k] = (-b - sqrt(d)) / (2 * a); 26 t2[k] = (-b + sqrt(d)) / (2 * a); 27 if(t2[k] <0) 28 return ; 29 t1[k] = max(0.0, t1[k]); 30 m++; 31 t1[m] = t1[k]; 32 t2[m] = t2[k]; 33 } 34 int main() { 35 scanf("%d%d%lf%lf%lf%lf", &n, &r, &bx, &by, &bvx, &bvy); 36 for(int i = 1; i <= n; i++) { 37 scanf("%lf%lf%lf%lf", &x[i], &y[i], &vx[i], &vy[i]); 38 calc(i); 39 } 40 for(int i = 1; i <= m; i++) { 41 ++cnt; 42 t[cnt] = t1[i]; 43 ++cnt; 44 t[cnt] = t2[i]; 45 } 46 sort(t + 1, t + cnt + 1); 47 int c = unique(t, t + cnt + 1) - t - 1; 48 for(int i = 1; i <= m; i++) { 49 int a = lower_bound(t + 1, t + c + 1, t1[i]) - t; 50 int b = lower_bound(t + 1, t + c + 1, t2[i]) - t; 51 in[a]++; 52 out[b]++; 53 } 54 int ans = 0, now = 0; 55 for(int i = 1; i <= c; i++) { 56 now += in[i]; 57 ans = max(ans, now); 58 now -= out[i]; 59 } 60 printf("%d\n", ans); 61 return 0; 62 } View Code
?
轉(zhuǎn)載于:https://www.cnblogs.com/ZJXXCN/p/10771266.html
總結(jié)
以上是生活随笔為你收集整理的bzoj [Usaco2009 Hol]Cattle Bruisers 杀手游戏的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 农行燃梦信用卡权益2018 银联VS万事
- 下一篇: android 资源