URAL 1348. Goat in the Garden 2[求点到线段的距离]
题目链接:http://acm.timus.ru/problem.aspx?space=1num=1348 题目的意思是:求一个点到线段的最短距离和最长距离。。 最长距离比较容易,就是求点到线段两个端点较长的那个距离就是ans。 最短距离就比较有意思了。。。 可能的情况就是点到线段的垂线的垂足
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1348
题目的意思是:求一个点到线段的最短距离和最长距离。。
最长距离比较容易,就是求点到线段两个端点较长的那个距离就是ans。
最短距离就比较有意思了。。。
可能的情况就是点到线段的垂线的垂足在线段内,还有就是垂足在线段外。。。
在线段内的话,那么应用叉积求面积+底面长度可以求得垂线长度也就是最短距离。。
如果在线段外的话,最短距离就是点到线段的两个端点的最小值。。
那么问题就来了。。怎么判断垂足在线段内还是在线段外的呢??
详细见代码。 - - 。。。
Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; const double eps = 1e-8; const double pi = acos(-1); //点 struct POINT { double x, y; POINT(){ } POINT(double a, double b){ x = a; y = b; } }; //线段 struct Seg { POINT a, b; Seg() { } Seg(POINT x, POINT y){ a = x; b = y; } }; //直线 struct Line { POINT a, b; Line() {} Line(POINT x, POINT y){ a = x; b = y; } }; //叉乘 double cross(POINT o, POINT a, POINT b) { return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y); } //求两点间的距离 double dis(POINT a, POINT b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } Seg s; POINT p; double L; //点到直线的距离.. double PointToLine(POINT p, Line l) { return fabs(cross(p, l.a, l.b)) / dis(l.a, l.b); } //线段到直线的距离.. double PointToSeg(POINT p, Seg s) { POINT tmp = p; tmp.x += s.a.y - s.b.y; tmp.y += s.b.x - s.a.x; if(cross(s.a, p, tmp) * cross(s.b, p, tmp) >= 0){ return min(dis(p, s.a), dis(p, s.b)); } return PointToLine(p, Line(s.a, s.b)); } void solve() { double ans1 = PointToSeg(p, s), ans2 = max(dis(p, s.a), dis(p, s.b)); printf("%.2lf\n%.2lf\n", ans1 > L ? ans1 - L : 0, ans2 > L ? ans2 - L : 0); return ; } int main() { // freopen("11.txt", "r", stdin); while(~scanf("%lf %lf %lf %lf", &s.a.x, &s.a.y, &s.b.x, &s.b.y)){ scanf("%lf %lf %lf", &p.x, &p.y, &L); solve(); } return 0; }</cmath></cstring></cstdio></algorithm></iostream>
--->
好吧,还需要好好的学习。。。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

What currency is THE? THE (Tokenized Healthcare Ecosystem) is a digital currency that uses blockchain technology to focus on innovation and reform in the healthcare industry. THE coin's mission is to use blockchain technology to improve the efficiency and transparency of the medical industry and promote more efficient cooperation among all parties, including patients, medical staff, pharmaceutical companies and medical institutions. The Value and Characteristics of THE Coin First of all, THE Coin, as a digital currency, has the advantages of blockchain - decentralization, high security, transparent transactions, etc., allowing participants to trust and rely on this system. Secondly, the uniqueness of THE coin is that it focuses on the medical and health industry, using blockchain technology to transform the traditional medical system and improve

DoNews reported on June 7 that the biggest shortcoming of the current GPT-4 model is mainly its arithmetic ability. Since the logical reasoning ability of the model needs to be improved, even for calculation problems that many people think are relatively simple, GPT-4 cannot get the correct answer. the result of. According to IT House reports, recently, researchers from the National University of Singapore launched the Goat model, saying that the model is "specifically used for arithmetic problems." The researchers stated that "after fine-tuning the LLaMA model, Goat achieved mathematically higher accuracy and better performance than GPT-4." The researchers proposed a new method to classify tasks according to the learnable types of arithmetic, and then use basic arithmetic principles to decompose unlearnable tasks into a series of learnable tasks (I

How to check the latest price of TheSandbox currency TheSandbox is a decentralized gaming platform built on the Ethereum blockchain. Land, assets and gaming experiences can be purchased using its native token SAND. The steps to check the latest price of SAND are as follows: Choose a reliable price check website or app. Some commonly used price query websites include: CoinMarketCap: https://coinmarketcap.com/Coindesk: https://www.coindesk.com/Binance: https://www.binance.com/ Search on the website or app SAND. View SAND

How to check the latest price of TheGraph coin? TheGraph is a decentralized protocol designed to provide efficient indexing and query services for blockchain data. The protocol is designed to make it easier for developers to build and launch decentralized applications (dApps), and to provide these applications with convenient access to blockchain data. To check the latest price of TheGraph Coin (GRT), you can follow these steps: Choose a reliable price checking website or app. Some commonly used price query websites include: CoinMarketCap: https://coinmarketcap.com/Coindesk: https://www.coind

Samsung plans to launch a new generation of Galaxy Z Fold and Flip 6 series folding screen smartphones in the second half of this year. Recently, Korean media TheElec and "Jiji Weekly e" revealed more details about these two new products. Samsung Galazy Z Fold6 leaked pictures. Source @chunvn8888 According to TheElec, Samsung Electronics’ supply chain manufacturers are expected to start the production of Galaxy Z Fold6 and Flip 6 related components in early May. In contrast, the production of parts for Galaxy Z Fold5 and Flip 5 started in the second half of May last year. This means that this year’s release schedule for the standard version of the Galaxy Z series is about two to three weeks earlier than last year. go

How to Check TheGraph Coin Market Cap TheGraph is a decentralized protocol designed to help developers index and query blockchain data. Its token GRT is used to pay network fees and reward node operators. How to check the market value of TheGraph currency: Choose a reliable website or platform: There are multiple websites and platforms that provide cryptocurrency market value information, such as CoinMarketCap, CoinGecko, Feixiaohao, etc. It is important to choose a reliable website or platform to ensure you are getting accurate information. Search for TheGraph: Search for GRT or TheGraph on the website or platform. View Market Cap: TheGraph’s market cap is often shown in search results. Tip: market capitalization

Recently, I read the enterprise desktop configuration white paper produced by Logitech in the first half of the year. The knowledge and purchasing logic involved in enterprise-level desktop peripherals gave us a lot of inspiration. Many of these fresh viewpoints are very suitable to be shared with old fans of Zhongguancun. Logitech White Paper: New Thoughts on Purchasing Desktop Peripherals As a leader in the field of desktop peripherals, Logitech’s brand strength and technological innovation are obvious to all. The significance of the release time of the white paper The release time of Logitech’s white paper coincides with the transformation of corporate office models. The popularity of hybrid office models poses new challenges for employer branding and talent attraction. New Trends in Desktop Peripheral Purchasing Previous desktop peripheral purchasing standards may have been too simplistic. Employees in different positions have significantly different needs for keyboards, mice, headsets and cameras. Perspectives in Logitech White Paper Logitech White
