第11届B组省赛 平面分割

在这里插入图片描述
推导背景: 增加的平面个数等于增加的交点个数加一
所以核心思想就变成了求解每次加入直线时新产生的交点个数;

让每次新加入的直线与之前的所有直线求交点
初始化v v里放的是新加入的节点增加的交点个数。
无交点 继续加入
有交点
判断是否有重点 有继续 没有加入v集合
直到当前直线与之前所有直线求过交点后,得出交点个数也就是v.size()为新加入直线后增加的交点个数。
ans做累计求和
接下来在此增加新的直线。
参考出处
题解:

#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 0x3f3f3f3f;
const int maxn = 1010;

int n, ans;
int a[maxn],b[maxn];
struct Point {
    double x, y;
};

bool isequal(Point a, Point b)
{
	return (abs(a.x - b.x) <= 1e-2 && abs(a.y - b.y) <= 1e-2);
}
Point crosspoint(int m, int n)
{
	double x1 = a[m],x2 = a[n],y1 = b[m],y2 = b[n];
	//平行则无交点
	if(x1 == x2)
	{
		return Point {INF,INF};
	}
	Point cp = Point();
	cp.x = (y2 - y1) /(x2 - x1);
	return cp;
}
int main() 
{	
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
	}
	ans = 2;
	for(int i = 2; i <= n; i++)
	{
		//新加入的i与之前的所有直线求焦点 不重复就放入v中;
		vector<Point> v;
		bool flag = false;
		for(int j = 1; j < i; j++)
		{
			Point now = crosspoint(i, j);
			if(now.x == INF || now.y == INF) continue;
			else
			{
				for(int k = 0; k < v.size(); k++)
				{
				//判断是否有重点 
					if(isequal(now,v[k])) flag = true;
				}
			}
			//没有就添加进入交点集合
			if(flag == false) v.push_back(now);
		}
		ans += v.size() + 1;
	}
	cout << ans << endl;
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

moumoumouwang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值