例题8-6(uva-1606)

#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 1024;
struct Node
{
	int x, y ,color;
	double value;
	bool operator<(const Node& in)const {
		return value < in.value;
	}
}input[maxn],cal[maxn];

int n;

bool IsLeft(Node& a, Node& b) {
	return a.x * b.y >= a.y * b.x;
}
int GetResult()
{
	if (n <= 2) return n;

	int ret = 0;
	for (int i = 0; i < n; i++) {
		//选择当前点作为原点
		int cnt = 0;
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			//平移到以上面选择的点作为原点
			cal[cnt].x = input[j].x - input[i].x;
			cal[cnt].y = input[j].y - input[i].y;
			//因为结果为隔板一边黑色个数 + 另一边的白色个数
			//把黑色的翻转的180 到一边 这样只用统计一边的就得到结果
			if (input[j].color) {
				cal[cnt].x = -cal[cnt].x;
				cal[cnt].y = -cal[cnt].y;
			}
			//计算极角
			cal[cnt].value = atan2(cal[cnt].y, cal[cnt].x);
			cnt++;
		}
		sort(cal, cal + cnt);
		int nStart = 0,nEnd = 0,nLast = cnt,tot = 2;
		while (nStart < nLast) {
			//在上一个点的基础上做旋转 因为上一个点满足的情况 当前的肯定满足 不管是角度一样还是 偏移了一点
			if (nStart == nEnd) {
				nEnd = (nEnd + 1) % cnt;
				++tot;
			}
			//选择当前点和原点连接形成的线作为隔板
			while (nStart != nEnd && IsLeft(cal[nStart], cal[nEnd])) {
				nEnd = (nEnd + 1) % cnt;
				tot++;
			}
			//当前点计算完毕 旋转到下一个点
			tot--;
			nStart++;
			ret = max(ret, tot);
		}
	}
	return ret;
}
int main()
{
	while (cin >> n && n) {
		for (int i = 0; i < n; i++) {
			cin >> input[i].x >> input[i].y >> input[i].color;
		}
		cout << GetResult() <<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值