当前位置:网站首页>[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;
}
边栏推荐
- neo4j安装教程
- Install mongdb tutorial and redis tutorial under Windows
- Software I2C based on Hal Library
- How to set up voice recognition on the computer with shortcut keys
- 數據庫高級學習筆記--SQL語句
- Solve the problem of installing failed building wheel for pilot
- 数据库高级学习笔记--SQL语句
- Valentine's Day flirting with girls to force a small way, one can learn
- 基于apache-jena的知识问答
- Base de données Advanced Learning Notes - - SQL statements
猜你喜欢

QT creator support platform

AcWing 1298. Solution to Cao Chong's pig raising problem

QT creator shape

AI benchmark V5 ranking

Integration test practice (1) theoretical basis

LeetCode #461 汉明距离

Summary of numpy installation problems

02 staff information management after the actual project

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

Neo4j installation tutorial
随机推荐
Some notes of MySQL
快来走进JVM吧
Pytorch基础
库函数--(持续更新)
Codeforces Round #753 (Div. 3)
Vs2019 use wizard to generate an MFC Application
Dotnet replaces asp Net core's underlying communication is the IPC Library of named pipes
Base de données Advanced Learning Notes - - SQL statements
搞笑漫画:程序员的逻辑
Armv8-a programming guide MMU (2)
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
Django运行报错:Error loading MySQLdb module解决方法
[free setup] asp Net online course selection system design and Implementation (source code +lunwen)
Asp access Shaoxing tourism graduation design website
解决安装Failed building wheel for pillow
vs2019 桌面程序快速入门
Did you forget to register or load this tag 报错解决方法
[Blue Bridge Cup 2017 preliminary] grid division
Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
人脸识别 face_recognition