当前位置:网站首页>[Bluebridge cup 2020 preliminary] horizontal segmentation
[Bluebridge cup 2020 preliminary] horizontal segmentation
2022-07-06 11:26:00 【%xiao Q】
subject
Title Description
There is... On the plane N A straight line , Among them the first i This straight line is y = Ai * x + Bi.
Please calculate these lines to divide the plane into several parts .
Input format
The first line contains an integer N.
following N That's ok , Each line contains two integers Ai, Bi.
about 50% The evaluation case of ,1 ≤ N ≤ 4, -10 ≤ Ai, Bi ≤ 10.
For all profiling use cases ,1 ≤ N ≤ 1000, -100000 ≤ Ai, Bi ≤ 100000.
Output format
An integer represents the answer .
sample input Copy
3
1 1
2 2
3 3
sample output Copy
6
analysis
First of all, we need to know a little common sense of Mathematics : In the same plane , If you add a line , It does not intersect all lines in the plane , Then a plane will be added , If it intersects with a straight line in this plane and produces intersections at different positions , Then an additional plane will be added .
Then we are in the process of making questions , Just judge whether to repeat the edge , Calculate the number of different intersections between the newly added line and the previous line , The heavy side is very good judgment , Just mark it with an array , We can also use set( It can automatically remove the weight ).
Reference code
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;
const int N = 1010;
typedef pair<double, double> PDD;
bool st[N]; // Used to mark heavy edges , Prevent double calculation of intersections
double a[N][2];
int main()
{
int n;
cin >> n;
int ans = 1; // At the beginning, there is a plane
rep(i, 1, n)
{
cin >> a[i][0] >> a[i][1];
set<PDD> point; // Calculate the number of different intersections between the line and the line in the plane
rep(j, 1, i - 1)
{
if(st[j]) continue;
if(a[i][0] == a[j][0])
{
if(a[i][1] == a[j][1])
{
st[i] = true;
break;
}
else continue;
}
double x = (a[i][1] - a[j][1]) / (a[j][0] - a[i][0]);
double y = a[i][0] * x + a[i][1];
point.insert({
x, y});
}
if(!st[i]) ans += point.size() + 1;
}
cout << ans << endl;
return 0;
}
边栏推荐
- When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
- Ansible实战系列一 _ 入门
- Principes JDBC
- vs2019 使用向导生成一个MFC应用程序
- Learn winpwn (3) -- sEH from scratch
- MySQL的一些随笔记录
- Nanny level problem setting tutorial
- 自动机器学习框架介绍与使用(flaml、h2o)
- Julia 1.6 1.7 common problem solving
- 數據庫高級學習筆記--SQL語句
猜你喜欢

Integration test practice (1) theoretical basis

vs2019 使用向导生成一个MFC应用程序

Leetcode 461 Hamming distance

Vs2019 desktop app quick start

Use dapr to shorten software development cycle and improve production efficiency

Did you forget to register or load this tag

Knowledge Q & A based on Apache Jena

机器学习--人口普查数据分析

02-项目实战之后台员工信息管理

In the era of DFI dividends, can TGP become a new benchmark for future DFI?
随机推荐
图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application
How to configure flymcu (STM32 serial port download software) is shown in super detail
Heating data in data lake?
Number game
AcWing 179.阶乘分解 题解
Basic use of redis
Test objects involved in safety test
软件测试-面试题分享
图片上色项目 —— Deoldify
数据库高级学习笔记--SQL语句
JDBC principle
[Thesis Writing] how to write function description of jsp online examination system
Learn winpwn (2) -- GS protection from scratch
Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
报错解决 —— io.UnsupportedOperation: can‘t do nonzero end-relative seeks
Why can't STM32 download the program
Double to int precision loss
PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt
Machine learning -- census data analysis