uva 10535 - Shooter(几何+最大区间覆盖)

737 篇文章 0 订阅
232 篇文章 0 订阅

题目链接:uva 10535 - Shooter


题目大意:给出若干堵墙(线段),然后给出人的位置,问说这个人最多开枪射穿几堵墙。


解题思路:最大区间覆盖问题的变形,首先把每堵墙转化成一个角度,然后计算角度区间的最大覆盖,注意:超过pi的要分成两个区间。


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>

using namespace std;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int N = 1005;

struct state {
	double t;
	int k;
}s[N*2];

struct point {
	double x1, x2, y1, y2;
}p[N];

int n, m;
double x, y;

bool cmp(const state& a, const state& b) {
	if (fabs(a.t - b.t) > eps) return a.t < b.t;
	return a.k > b.k;
}

void init() {
	m = 0;
	for (int i = 0; i < n; i++) 
		scanf("%lf%lf%lf%lf", &p[i].x1, &p[i].y1, &p[i].x2, &p[i].y2);
	scanf("%lf%lf", &x, &y);

	for (int i = 0; i < n; i++) {
		double l = atan2(p[i].y1 - y, p[i].x1 - x);
		double r = atan2(p[i].y2 - y, p[i].x2 - x);
		if (l > r) swap(r, l);		
		if (r - l >= pi) {
			s[m].t = -pi; s[m++].k = 1;
			s[m].t = l;   s[m++].k = -1;
			l = r; r = pi;
		}
		s[m].t = l; s[m++].k = 1;
		s[m].t = r; s[m++].k = -1;
	}
	sort(s, s + m, cmp);
}

int solve() {
	int ans = 0, c = 0;
	for (int i = 0; i < m; i++) {
		c += s[i].k;
		ans = max(ans, c);
	}
	return ans;
}

int main() {
	while (scanf("%d", &n) == 1 && n) {
		init();
		printf("%d\n", solve());
	}
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Zombie Raid is a thrilling top-down shooter survival game set in a post-apocalyptic world overrun by zombies. The game features fast-paced action, challenging gameplay, and a variety of weapons and power-ups to help you survive. As a survivor, your goal is to protect your base from the endless waves of zombies. You'll need to use your wits and quick reflexes to stay alive and fend off the undead hordes. The game features a variety of weapons, from pistols and shotguns to assault rifles and rocket launchers, to help you take down the zombies. In addition to weapons, you can also collect power-ups like health kits, ammo crates, and special abilities to help you survive. These power-ups can be found scattered throughout the game world, so be sure to explore and scavenge as much as possible. Zombie Raid also features a variety of enemies, from slow-moving zombies to fast and agile ones, as well as bosses that require strategy and skill to defeat. You'll need to adapt to each new wave of enemies and use different tactics to survive. The game also features multiple levels, each with its own unique challenges and objectives. As you progress through the game, you'll unlock new weapons and abilities, making it easier to take on the hordes of zombies. Overall, Zombie Raid is a fun and exciting top-down shooter survival game that will keep you on the edge of your seat. With its challenging gameplay, variety of weapons and power-ups, and endless waves of zombies, it's a game that's sure to keep you entertained for hours on end.
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值