The Parallel Challenge Ballgame[HDU1101]
2016-12-01 16:38
99 查看
The Parallel Challenge Ballgame
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 547 Accepted Submission(s): 26
Problem Description
Before the ACM/ICPC world final 2005, there is a competition called “The Parallel Challenge Ballgame”. The Parallel Challenge ballgame gives each team a chance to pit their programming skills against those of other teams in a fast-moving parallel-programming game of skill, treachery, and hazard avoidance. Each team will write a single C++ class named MyPlayer which defines the characteristics of a “player”. The MyPlayer class will be instantiated five times in the environment, making up a five-player team, which will then compete in a series of Parallel Challenge ballgames running on an IBM Power Architecture Blue Gene supercomputer – the world’s fastest computer.
A Parallel Challenge ballgame is played on a rectangular filed. The filed is surrounded by a wall; balls will bounce off the walls if they run into it. The rule of bouncing is the same as light (In figure 1,angle 1 equals angle 2). Near the edges of the fields are a number of goals where points can be scored. Goals are rectangular areas lying near the edges of the field but within the field boundaries. When the game starts there are a number of balls placed at random locations on the field. A player can move to a ball, pick it up, and throw (of course, it is not football, why not use hand?) it. At the start of each game there are also a number of “nets” distributed at various locations on the edges of the field. A player can move to and pick up one of these nets, and can then use them to “trap” players on other teams by throwing the net on top of them. Once a player is trapped beneath a net, that player cannot do anything more in the game until a teammate comes and lifts the net from the trapped player. A player may “tackle” another player, normally in an attempt to dislodge a ball being carried by the other player (although it is also legal to tackle a player who is not carrying a ball).
View Code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 547 Accepted Submission(s): 26
Problem Description
Before the ACM/ICPC world final 2005, there is a competition called “The Parallel Challenge Ballgame”. The Parallel Challenge ballgame gives each team a chance to pit their programming skills against those of other teams in a fast-moving parallel-programming game of skill, treachery, and hazard avoidance. Each team will write a single C++ class named MyPlayer which defines the characteristics of a “player”. The MyPlayer class will be instantiated five times in the environment, making up a five-player team, which will then compete in a series of Parallel Challenge ballgames running on an IBM Power Architecture Blue Gene supercomputer – the world’s fastest computer.
A Parallel Challenge ballgame is played on a rectangular filed. The filed is surrounded by a wall; balls will bounce off the walls if they run into it. The rule of bouncing is the same as light (In figure 1,angle 1 equals angle 2). Near the edges of the fields are a number of goals where points can be scored. Goals are rectangular areas lying near the edges of the field but within the field boundaries. When the game starts there are a number of balls placed at random locations on the field. A player can move to a ball, pick it up, and throw (of course, it is not football, why not use hand?) it. At the start of each game there are also a number of “nets” distributed at various locations on the edges of the field. A player can move to and pick up one of these nets, and can then use them to “trap” players on other teams by throwing the net on top of them. Once a player is trapped beneath a net, that player cannot do anything more in the game until a teammate comes and lifts the net from the trapped player. A player may “tackle” another player, normally in an attempt to dislodge a ball being carried by the other player (although it is also legal to tackle a player who is not carrying a ball).
#include <math.h> #include <stdio.h> #define eps (1e-8) #define pi 3.1415926536 struct rectangle { double x1, x2, y1, y2; } b, g[800]; double x, y, l[1005], r[1005]; void adjust(rectangle & r) { double t; if (r.x1 - r.x2 > eps) { t = r.x1; r.x1 = r.x2; r.x2 = t; } if (r.y1 - r.y2 > eps) { t = r.y1; r.y1 = r.y2; r.y2 = t; } } int pos(rectangle a) { if ((a.x1 - x <= eps) && (x - a.x2 <= eps) && (a.y1 - y <= eps) && (y - a.y2 <= eps)) { return 0; } if (x - a.x1 < eps) { if (y > a.y2) { return 8; } else if (y - a.y1 < eps) { return 6; } else { return 7; } } else if (x - a.x2 > eps) { if (y > a.y2) { return 2; } else if (y - a.y1 < eps) { return 4; } else { return 3; } } else { if (y - a.y2 > eps) { return 1; } else { return 5; } } } int main() { int T, n; scanf("%d", &T); while (T--) { scanf("%lf%lf%lf%lf", &b.x1, &b.y1, &b.x2, &b.y2); adjust(b); scanf("%lf%lf%d", &x, &y, &n); for (int i = 1; i <= n; i++) { scanf("%lf%lf%lf%lf", &g[i].x1, &g[i].y1, &g[i].x2, &g[i].y2); adjust(g[i]); g[i + n].x1 = g[i].x1; g[i + n].y1 = 2 * b.y1 - g[i].y1; g[i + n].x2 = g[i].x2; g[i + n].y2 = 2 * b.y1 - g[i].y2; adjust(g[i + n]); g[i + 2 * n].x1 = g[i].x1; g[i + 2 * n].y1 = 2 * b.y2 - g[i].y1; g[i + 2 * n].x2 = g[i].x2; g[i + 2 * n].y2 = 2 * b.y2 - g[i].y2; adjust(g[i + 2 * n]); g[i + 3 * n].x1 = 2 * b.x1 - g[i].x1; g[i + 3 * n].y1 = g[i].y1; g[i + 3 * n].x2 = 2 * b.x1 - g[i].x2; g[i + 3 * n].y2 = g[i].y2; adjust(g[i + 3 * n]); g[i + 4 * n].x1 = 2 * b.x2 - g[i].x1; g[i + 4 * n].y1 = g[i].y1; g[i + 4 * n].x2 = 2 * b.x2 - g[i].x2; g[i + 4 * n].y2 = g[i].y2; adjust(g[i + 4 * n]); } n *= 5; int m = 0; bool flag = false; double a1, a2; for (int i = 1; i <= n; i++) { int tmp = pos(g[i]); if (tmp == 0) { flag = true; break; } else if (tmp == 1) { m++; a1 = atan2(y - g[i].y2, x - g[i].x1); a2 = atan2(y - g[i].y2, g[i].x2 - x); l[m] = pi + a1; r[m] = 2 * pi - a2; } else if (tmp == 2) { m++; a1 = atan2(y - g[i].y2, x - g[i].x1); a2 = atan2(x - g[i].x2, y - g[i].y1); l[m] = pi + a1; r[m] = 1.5 * pi - a2; } else if (tmp == 3) { m++; a1 = atan2(x - g[i].x2, g[i].y2 - y); a2 = atan2(x - g[i].x2, y - g[i].y1); l[m] = 0.5 * pi + a1; r[m] = 1.5 * pi - a2; } else if (tmp == 4) { m++; a1 = atan2(x - g[i].x2, g[i].y2 - y); a2 = atan2(g[i].y1 - y, x - g[i].x1); l[m] = 0.5 * pi + a1; r[m] = pi - a2; } else if (tmp == 5) { m++; a1 = atan2(g[i].y1 - y, g[i].x2 - x); a2 = atan2(g[i].y1 - y, x - g[i].x1); l[m] = a1; r[m] = pi - a2; } else if (tmp == 6) { m++; a1 = atan2(g[i].y1 - y, g[i].x2 - x); a2 = atan2(g[i].x1 - x, g[i].y2 - y); l[m] = a1; r[m] = 0.5 * pi - a2; } else if (tmp == 7) { m++; a1 = atan2(g[i].y2 - y, g[i].x1 - x); l[m] = 0; r[m] = a1; m++; a2 = atan2(y - g[i].y1, g[i].x1 - x); l[m] = 2 * pi - a2; r[m] = 2 * pi; } else { m++; a1 = atan2(g[i].x1 - x, y - g[i].y1); a2 = atan2(y - g[i].y2, g[i].x2 - x); l[m] = 1.5 * pi + a1; r[m] = 2 * pi - a2; } } if (flag) { printf("100.00%%\n"); } else { double tot = 0, t, ll, rr; for (int i = 1; i < n; i++) { for (int j = i + 1; j <= n; j++) { if (l[i] - l[j] > eps) { t = l[i]; l[i] = l[j]; l[j] = t; t = r[i]; r[i] = r[j]; r[j] = t; } } } ll = l[1]; rr = r[1]; m++; l[m] = 361; r[m] = 461; for (int i = 2; i <= m; i++) { if (l[i] - rr <= eps) { if (rr - r[i] < eps) { rr = r[i]; } } else { tot += (rr - ll); ll = l[i]; rr = r[i]; } } printf("%.2lf%%\n", tot * 50 / pi); } } return 0; }
View Code
相关文章推荐
- The Parallel Challenge Ballgame
- 【bzoj2091】【Poi2010】【The Minima Game】【dp】
- hdu 4605 Magic Ball Game
- The Rotation Game UVA - 1343
- hdu 1556 Color the ball(线段树or树状数组)
- Building a WPF Sudoku Game: Part 5 - The AI Battle: Loading and Comparing AI Plug-ins (zz)
- hdu 1556 Color the ball
- UVA - 1343 The Rotation Game
- The Rock Game
- hdu1556 Color the ball (树状数组)
- hdu 1556 Color the ball
- hdoj 2277 Change the ball【规律题】
- HDU 1556 Color the ball
- 深入解读AlphaGo,Nature-2016:Mastering the game of Go with deep neural networks and tree search
- Hack The Game 通关记录
- Ball Blasting Game UVA - 12378 (马拉车)
- 教程Roll-a-ball tutorialMoving the Player 解读
- [HDU1556] Color the ball - 树状数组
- 【HDOJ】4605 Magic Ball Game
- STM32F4: Generating parallel signals with the FSMC