UVA 972 Horizon Line

继续扫描线。这题我做的挺鸡肋的,离散化+扫描线了。

然后扫描线一段一段找。。

其实我觉得存成线段的那些点应该会好做点。。这么做好纠结滴说。

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")

using namespace std;

const int MAX = 110;
const double inf = 1e30;
struct point {double x,y;};
point f[MAX],g[MAX];
double x[MAX*2];

int main()
{
	int n,m;
	
	while( ~scanf("%d",&n) )
	{
		int cnt = 0;
		double sx = 0;
		x[cnt++] = 0;
		for(int i=0; i<n; i++)
		{
			scanf("%lf%lf",&f[i].x, &f[i].y);
			sx += f[i].y;
			x[cnt++] = sx;
		}
		scanf("%d",&m);
		
		sx = 0;
		for(int i=0; i<m; i++)
		{
			scanf("%lf%lf",&g[i].x, &g[i].y);
			sx += g[i].y;
			x[cnt++] = sx;
		}
		
		sort(x, x+cnt);
		cnt = unique(x, x+cnt) - x;
		
		int ff = 0,gg = 0;
		double fx = 0, gx = 0;
		double h = 0,minh = inf;
		for(int i=0; i<cnt; i++)
		{
			while( fx <= x[i] && ff < n )
			{
				fx += f[ff].y;
				ff++;
			}
			while( gx <= x[i] && gg < m )
			{
				gx += g[gg].y;
				gg++;
			}
			h = max(f[ff-1].x, g[gg-1].x);
			minh = min(h, minh);
		}
		
		printf("%.3lf\n", minh);
	}

return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值