1. 程式人生 > >UVA - 12304 2D Geometry 110 in 1!

UVA - 12304 2D Geometry 110 in 1!

題面

題意

計算幾何模板題,一共有六種操作:
1.給出三個點,求它們的外接圓。
2.給出三個點,求它們的內切圓。
3.給出一個點個一個圓,求過這個點且與圓相切的直線與X軸的夾角。
4.給出一給點,一條線和r,求半徑為r且與這條直線相切並過這個點的圓的圓心座標。
5.給出兩條直線和r,求半徑為r且同時與這兩條直線相切的圓的圓心座標。
6.給出兩個圓和r,求半徑為r且同時與這兩個圓相切的圓的圓心座標。
如有多個答案,從小到大以此輸出。

程式碼

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring> #include<vector> #include<algorithm> #define eps 1e-10 #define pi 3.14159265358979 #define db double using namespace std; char str[110]; struct Node { db x,y; void in(){scanf("%lf%lf",&x,&y);} bool operator < (const Node &u) const{if(fabs(x-u.x)>
eps) return x<u.x;return y<u.y;} Node operator + (const Node &u) const{Node res;res.x=x+u.x,res.y=y+u.y;return res;} Node operator - (const Node &u) const{Node res;res.x=x-u.x,res.y=y-u.y;return res;} db operator * (const Node &u) const{return x*u.x+y*u.y;} Node operator * (const
db &u) const{Node res;res.x=x*u,res.y=y*u;return res;} Node operator / (const db &u) const{Node res;res.x=x/u,res.y=y/u;return res;} }; struct Xn { Node num,v; }; vector<Node>res; inline db cj(Node u,Node v){return u.x*v.y-u.y*v.x;}//叉積 inline db lenf(Node u,Node v){return (u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y);}//兩點間距離的平方 inline db len(Node u,Node v){return sqrt(lenf(u,v));}//兩點間距離 inline Node make(db u,db v) { Node res; res.x=u,res.y=v; return res; } inline Node rot(Node u)//將一條直線旋轉90度 { Node res; res.x=-u.y; res.y=u.x; return res; } inline Node jd(Xn u,Xn v)//求兩直線的交點 { Node res; db t=(cj(u.num,u.v)-cj(v.num,u.v))/cj(v.v,u.v); return v.v*t+v.num; } inline bool up(Node u,Xn v)//判斷某個點是否在某條直線的上方 { db t=u.y+(u.x-v.num.x)/v.v.x*v.v.y-v.num.y; return t>eps; } inline bool on(Node u,Xn v)//判斷某個點是否在某條直線上 { db t=u.y+(u.x-v.num.x)*v.v.y/v.v.x-v.num.y; return t>-eps&&t<eps; } namespace wjy//外接圓 { Node a,b,c,ans; Xn p,q; void work() { a.in(),b.in(),c.in(); p.num=(a+c)/2,p.v=rot(c-a); q.num=(a+b)/2,q.v=rot(b-a); ans=jd(p,q); printf("(%.6f,%.6f,%.6f)\n",ans.x,ans.y,len(ans,a)); } } namespace nqy//內切圓 { Node a,b,c,ans; Xn p,q; db r; inline Xn jpfx(Node w,Node u,Node v) { Xn p,q,res; db t; res.num=p.num=q.num=w; p.v=u-w,q.v=v-w; t=len(u,w)/len(v,w); q.v=q.v*t; res.v=p.v+q.v; return res; } void work() { a.in(),b.in(),c.in(); p=jpfx(a,b,c),q=jpfx(b,a,c); ans=jd(p,q); r=fabs(cj(b-a,c-a))/(len(a,b)+len(b,c)+len(a,c)); printf("(%lf,%lf,%lf)\n",ans.x,ans.y,r); } } namespace qxjj//求過某個點且與圓相切的直線與X軸的夾角。 { Node a,b,c,res1,res2; db r,t,r1,r2,l,ans1,ans2; Xn p,q; inline db zh(db u) { u=u/pi*180; for(;u<0;u+=180); for(;u>180;u-=180); return u; } void work() { a.in(); scanf("%lf",&r1); b.in(); l=len(a,b); if(l*l<r1*r1-eps) { puts("[]"); return; } if(l*l<r1*r1+eps) { p.v=rot(b-a); p.num=b; printf("[%lf]\n",zh(atan(p.v.y/p.v.x))); return; } r2=sqrt(l*l-r1*r1); t=r2/r1; c=(b-a)/(1+t*t)+a; p.num=c,p.v=c-a; p.v=rot(p.v); t=l*t/(1+t*t); res1=p.num+p.v*t/sqrt(p.v*p.v); p.v=rot(rot(p.v)); res2=p.num+p.v*t/sqrt(p.v*p.v); p.num=q.num=b; p.v=b-res1,q.v=b-res2; ans1=zh(atan(p.v.y/p.v.x)),ans2=zh(atan(q.v.y/q.v.x)); if(ans1>ans2) swap(ans1,ans2); printf("[%lf,%lf]\n",ans1,ans2); } } namespace gdxq//求過某個點並與某直線相切的圓 { Node cen,a,b,c,res1,res2,o; Xn p,q; db r,t; void work() { cen.in(),a.in(),b.in(); scanf("%lf",&r); p.num=a,p.v=b-a; if(on(cen,p)) { p.num=cen; p.v=rot(p.v); t=r/sqrt(p.v*p.v); res1=p.num+p.v*t; res2=p.num-p.v*t; if(res2<res1) swap(res1,res2); printf("[(%lf,%lf),(%lf,%lf)]\n",res1.x,res1.y,res2.x,res2.y); return; } q.v=rot(p.v); q.num=cen; o=jd(p,q); q.num=o; q.v=cen-o; t=r/sqrt(q.v*q.v); c=q.num+q.v*t; if(r*r+eps<lenf(cen,c)) { puts("[]"); return; } t=sqrt(r*r-lenf(cen,c))/sqrt(p.v*p.v); if(t<eps) { printf("[(%lf,%lf)]\n",c.x,c.y); return; } res1=c+p.v*t; res2=c-p.v*t; if(res2<res1) swap(res1,res2); printf("[(%lf,%lf),(%lf,%lf)]\n",res1.x,res1.y,res2.x,res2.y); } } namespace ylxq//求與兩直線相切的圓 { Node a,b,c,d; Xn o,p,q,p1,p2,q1,q2; db t,r; void work() { int i,j; a.in(),b.in(); p.num=a,p.v=b-a; a.in(),b.in(); scanf("%lf",&r); q.num=a,q.v=b-a; o=p,o.v=rot(p.v); t=r/sqrt(o.v*o.v); o.v=o.v*t; p1.num=p.num+o.v,p1.v=p.v; p2.num=p.num-o.v,p2.v=p.v; o=q,o.v=rot(q.v); t=r/sqrt(o.v*o.v); o.v=o.v*t; q1.num=q.num+o.v,q1.v=q.v; q2.num=q.num-o.v,q2.v=q.v; res.clear(); res.push_back(jd(p1,q1)); res.push_back(jd(p1,q2)); res.push_back(jd(p2,q1)); res.push_back(jd(p2,q2)); sort(res.begin(),res.end()); printf("["); for(i=0;i<res.size();i++) { if(i) printf(","); printf("(%lf,%lf)",res[i].x,res[i].y); } printf("]\n"); } } namespace ylyq//求與兩圓相切的圓 { Node o1,o2,a,b; Xn p,q; db r1,r2,r,d,t,l,ca; void work() { o1.in(),scanf("%lf",&r1); o2.in(),scanf("%lf",&r2); scanf("%lf",&r); r1+=r,r2+=r; l=len(o1,o2); if(r1+r2+eps<l || fabs(r1-r2)>l+eps) { puts("[]"); return; } ca=(lenf(o1,o2)+r1*r1-r2*r2)/(2*l*r1); d=t=r1*ca; p.num=o1; p.v=o2-o1; t=t/sqrt(p.v*p.v); q.num=p.num+p.v*t; q.v=rot(p.v); t=sqrt(r1*r1-d*d); t=t/sqrt(q.v*q.v); q.v=q.v*t; a=q.num+q.v; b=q.num-q.v; if(b<a) swap(a,b); printf("[(%lf,%lf)",a

相關推薦

UVA - 12304 2D Geometry 110 in 1!

題面 題意 計算幾何模板題,一共有六種操作: 1.給出三個點,求它們的外接圓。 2.給出三個點,求它們的內切圓。 3.給出一個點個一個圓,求過這個點且與圓相切的直線與X軸的夾角。 4.給出一給點,一條線和r,求半徑為r且與這條直線相切並過這個點的圓的圓心座標。 5.給出兩條直線和

UVa 1585 Score(習題3-1

一道比較水的題目,很久之前自己寫了程式碼的所以直接複製上來吧 關鍵的地方就是計算'O'連續出現的次數 才發現之前已經發過一遍了,那麼這個就當是完善一下之前一些地方吧 程式碼; #include<iostream> #include<cstdio> #i

Ionic 3 / Angular 5 UI Theme / Template App - 5 in 1 Multipurpose Starter iOS 12 Style App

Live PreviewScreenshots   Share  Facebook Google Plus Twitter Pinterest Add to Favorites Add to Collection

10000000 in 1

doit.cpp #include <stdio.h> #include <vector> #include <sstream> #include <fstream> #include <string> #includ

Open CASCADE Modeling Data – 2D Geometry

Open CASCADE Modeling Data – 2D Geometry 一、概述 Overview 在建立幾何物件之前,必須要考慮怎樣來處理之。包Geom2d提供了比包gp範圍更廣的幾何物件。這些物件都是以引用的方式來處理而不是值。當複製一個物件時,並不是物件的值,所以改變一個複製的例項的值,會影響

Vue.js — There and Back Again in 1.5 years

Get up to speedBy using the Vue.js’ webpack template we hit the ground running. This meant menial tasks had already been done to an agreeable extent by som

Get a Ninja 2-in-1 blender on sale at Walmart for $49 (and save $40) ahead of Cyber Monday

Sometimes you need your blender to be more than a blender. The Nutri Ninja 2-in-1 Blender is not only a single-serve blender perfect for smoothies and milk

論文閱讀:Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour

論文首先提出了神經網路訓練的一個不好的現象:batch size的增大到一定程度,ResNet的分類準確率會下降。這個現象推翻了我以前的一個直覺:覺得batch size大,訓練的效果會更好。 為了加快訓練的速度(增大batch size)同時保證準確率,論文

論文:accurate ,large minibatch SGD:Training ImageNet in 1 Hour

Abstract:這篇論文發現,在 ImageNet dataset 上使用 large minibatch 會導致優化困難,但是當這個問題解決了,模型具有更好的泛化能力,並且沒有精度上的損失為達到這個目的,我們提出了 hyper-parameter-free linear

UVa LA 4094 WonderTeam 構造 難度: 1

int scanf 球隊 namespace problem 結果 () == 得到 題目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=

解決mysql報錯:- Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ'

_for tran contains column schema mysql eat table express mysql執行報錯: - Expression #1 of ORDER BY clause is not in GROUP BY clause and cont

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)

clas mysq mic swd pass pan 天使 -1 root 今天使用MySQLdb往MySQL插入中文數據遇到一個異常: UnicodeEncodeError: ‘latin-1‘ codec can‘t encode characters in posit

uva 10340 all in all

() ring ace while clu return include all urn #include<bits/stdc++.h> using namespace std; bool cmpare(string t,string s) { int

UVA 11762 - Race to 1(概率)

idt font tle class table review prim name scan UVA 11762 - Race to 1 題意:給定一個n,每次隨即選擇一個n以內的質數,假設不是質因子,就保持不變,假設是的話。就把n除掉該因子,問n變成1的次數的期望

編譯安裝libiconv報錯:./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)

編譯安裝libiconv報錯:./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)錯誤如下: In file included from progname.c:26:0: ./stdio.h:101

Testlink安裝:Notice:Undefined index: type in C:inetpubwwwroot estlink-1.9.3installinstallCheck.php on line 41

ndk coq vip cbt fhq mft ryu base64 gb2 問題現象: 問題原因:php配置參數中錯誤提示顯示; 問題解決:修改php.ini配置文件,修改為如下: error_reporting = E_ALL & ~E_NOTICE

Invalid Subledger (XLA) Packages In Release 12.1.3

see pen names cti nes confirm conf doc tdi In this Document Goal Solution 1.- Information

Found 1 slaves: Use of uninitialized value in printf at /usr/local/percona-toolkit/bin/pt-online-schema-change line 8489

console val take file logs printf nbsp found try 1. problem description: as the title show, i miss the first problem using pt-online-s

R in action -- 第1

以及 span spa rar clas start 數據分析工具 blog 有效 R in action -- 第1章 R語言介紹 R:一個數據分析和圖形顯示的程序設計環境 R 環境 R 環境由一組數據操作,計算和圖形展示的工具構成。相對其他同類軟件,它的 特色在於:

R in action -- 2.1 數據結構

ram style 處理 cells bsp 創建 通過 不同 div R in action -- 2.1 數據結構 1、R中用來存儲數據的結構:標量、向量、數組、數據框、列表。 2、R中可以處理的數據類型:數值、字符、邏輯、復數、原生(字節)。 3、向量: 向量是用來