UVALive - 3905 Meteor

题目

思路:

得出每个流星出现在长方形内部的进入、退出时间并存起来。

按时间从小到大,遇到进入时间就+1,遇到退出时间就-1。

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vll;

const int MAXN = 1e6 + 10;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const double eps = 1e-8;

int n, m, k;

typedef struct Node{
	double val;
	int type, id;
	Node(double a, int b, int c){
		val = a;
		type = b;
		id = c;
	}
	bool operator < (const Node &rhs) const{
		if(fabs(val - rhs.val) < eps)
			return type < rhs.type;
		return val - rhs.val > -eps;
	}
}Node;

int w, h;

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << setprecision(10) << fixed;
	int times;
	cin >> times;
	while(times--){
		priority_queue<Node> q;
		cin >> w >> h >> n;
		for(int i = 0; i < n; i++){
			int x, y, a, b;
			cin >> x >> y >> a >> b;
			if((x < 0 && a <= 0) || (x > w && a >= 0) || (y < 0 && b <= 0) || (y > h && b >= 0) || (x == 0 && a == 0) || (x == w && a == 0) || (y == 0 && b == 0) || (y == h && b == 0))
				continue;
			double x1 = x > 0 && x < w ? 0 : (double)min(abs(x), abs(x - w)) / abs(a);
			double x2 = a ? max((double)-x / a, (double)(w - x) / a) : INF;
			double y1 = y > 0 && y < h ? 0 : (double)min(abs(y), abs(y - h)) / abs(b);
			double y2 = b ? max((double)-y / b, (double)(h - y) / b) : INF;
			double u = max(x1, y1);
			double v = min(x2, y2);
//			cerr << i << " " << u << " " << v << endl;
			if(u - v > -eps)
				continue;
			q.push(Node(u, 0, i + 1));
			q.push(Node(v, 1, i + 1));
		}
		int res, cur;
		res = cur = 0;
		while(!q.empty()){
			cur += q.top().type * (-2) + 1;
			res = max(res, cur);
			q.pop();
		}
		cout << res << endl;
	}
	cerr << "execute time : " << (double)clock() / CLOCKS_PER_SEC << endl;
	return 0;
}

 

未来可期。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值