南阳理工12题

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
double r, x, y, width, height;
class Circle
{
public:
	Circle(double x, double r) :x(x), r(r){}
	double Left() const
	{
		if (r*r - height*height / 4<0) 
			return x; 
		return x - sqrt(r*r - (height*height / 4));
	}
	double Right() const
	{ 
		if (r*r - height*height / 4<0) 
		return x; 
	return x + sqrt(r*r - (height*height / 4)); 
	}
	friend ostream & operator<<(ostream& out, const Circle& circle);
private:
	double x, r;
};
ostream & operator<<(ostream& out, const Circle& circle)
{
	out << circle.x << " " << circle.r;
	return out;
}
struct CircleLess
{
	bool operator()(const Circle& c1, const Circle& c2)
	{
		return c1.Right()<c2.Right();
	}
};

int main()
{

	int m;
	cin >> m;
	while (m--)
	{
		int n;

		vector<Circle> Rs;
		cin >> n >> width >> height;
		Rs.reserve(n);


		while (n--)
		{
			cin >> x >> r;
			Rs.push_back(Circle(x, r));
		}
		sort(Rs.begin(), Rs.end(), CircleLess());
		vector<int> choosed;
		choosed.push_back(-1);
		double len = 0;
		try{
			while (len<width)
			{
				int last = -1;
				for (vector<Circle>::size_type i = choosed.back() + 1; i != Rs.size(); i++)
				{
					if (Rs[i].Left() <= len)
					{
						//cout<<Rs[i].Left()<<endl;
						last = i;
					}
				}
				if (last == -1) throw - 1;
				else
				{
					choosed.push_back(last);
					len = Rs[last].Right();
				}
			}
			cout << choosed.size() - 1 << endl;

		}
		catch (...)
		{
			cout << 0 << endl;
		}
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值