山東省第四屆ACM大學生程式設計競賽-Rescue The Princess(計算幾何)
Rescue The Princess
Time Limit: 1000ms Memory limit: 65536K 有疑問?點這裡^_^
題目描述
Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immediately. Yet, the beast set a maze. Only if the prince find out the maze’s exit can he save the princess.
Now, here comes the problem. The maze is a dimensional plane. The beast is smart, and he hidden the princess snugly. He marked two coordinates of an equilateraltriangle in the maze. The two marked coordinates are A(x1,y1) and B(x2,y2). The third coordinate C(x3,y3) is the maze’s exit. If the prince can find out the exit, he can save the princess. After the prince comes into the maze, he finds out the A(x1,y1) and B(x2,y2), but he doesn’t know where the C(x3,y3) is. The prince need your help. Can youcalculate the C(x3,y3) and tell him?
輸入
The first line is an integer T(1 <= T <= 100) which is the number of test cases. T test cases follow. Each test case contains two
coordinates A(x1,y1) and B(x2,y2), described by four floating-point numbers x1, y1, x2, y2 ( |x1|, |y1|, |x2|, |y2|<=
1000.0).
Please notice that A(x1,y1) and B(x2,y2) and C(x3,y3) are in an anticlockwise
direction from the equilateraltriangle. And coordinates A(x1,y1) and B(x2,y2)
are given by anticlockwise.
輸出
示例輸入
4 -100.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 0.00 0.00 100.00 100.00 1.00 0.00 1.866 0.50
示例輸出
(-50.00,86.60) (-86.60,50.00) (-36.60,136.60) (1.00,1.00)
提示
來源
題目意思:
給定A、B兩個點的座標,求另外一個點C,使得ABC構成一個等邊三角形,且ABC三點是逆時針順序。
解題思路如圖(From 隊友大神CXF):

注意到數學反三角函式double atan2 (double, double); 反正切(整圓值), 結果介於[-PI/2, PI/2]
區別於double atan (double); 反正切(主值), 結果介於[-PI/2, PI/2],因為斜率為零的情況atan2不返回0而不是錯誤值。
/*
* Copyright (c) 2016, 煙臺大學計算機與控制工程學院
* All rights reserved.
* 檔名稱:cal.cpp
* 作 者:單昕昕
* 完成日期:2016年4月9日
* 版 本 號:v1.0
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const double PI=acos(-1.0);
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
double l=sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
double s=atan2(y2-y1,x2-x1);
double l1=l*sin(s+(PI/3.0));
double l2=l*cos(s+(PI/3.0));
double x=x1+l2;
double y=y1+l1;
printf("(%.2lf,%.2lf)\n",x,y);
}
return 0;
}
相關文章
- 第十屆山東省大學生程式設計競賽題解(A、F、M、C)程式設計
- 第15屆浙江省大學生程式設計競賽D題程式設計
- 第二十屆西南科技大學ACM程式設計競賽(同步賽)ACM程式設計
- [題解][2021-2022年度國際大學生程式設計競賽第10屆陝西省程式設計競賽] Type The Strings程式設計
- 無錫學院2024年ACM大學生程式設計競賽校選賽 題解ACM程式設計
- 2019山東ACM省賽補題題解ACM
- 紹興市大學生程式設計競賽程式設計
- 2020 年第一屆遼寧省大學生程式設計競賽 D.開心消消樂(點分治)程式設計
- 第 10 屆 CCPC 中國大學生程式設計競賽濟南站 遊記程式設計
- 華中農業大學第十三屆程式設計競賽程式設計
- [補題] 第 45 屆國際大學生程式設計競賽(ICPC)亞洲區域賽(上海)程式設計
- 第十屆中國大學生程式設計競賽 重慶站(CCPC 2024 Chongqing Site)程式設計
- 2024 CCPC第五屆遼寧省程式設計競賽 集訓2程式設計
- 第43屆ACM-ICPC國際大學生程式設計競賽 亞洲區域賽南京站現場賽名額分配相關說明ACM程式設計
- 華中農業大學第十三屆程式設計競賽 題解程式設計
- 24山東省賽wp
- 中國計量大學現代科技學院第四屆“中競杯”程式設計校賽(同步賽) F.爬塔(DP)程式設計
- 【比賽覆盤】2024第七屆“傳智杯”全國大學生計算機大賽程式設計挑戰賽(初賽第一場)計算機程式設計
- 北京資訊科技大學第十一屆程式設計競賽(重現賽)I程式設計
- 大學生電子設計競賽電源資料
- 第十七屆中國計量大學程式設計競賽 I- Isolated Pointset程式設計
- 第十五屆浙江大學寧波理工學院程式設計大賽(同步賽)程式設計
- QZEZ第一屆“飯吉圓”杯程式設計競賽程式設計
- 計算幾何
- 九州信泰杯 第十一屆山東省網路安全技能大賽
- 第二屆“祥雲杯”網路安全大賽暨吉林省第四屆大學生網路安全大賽火熱報名中
- 2020年“感恩杯”台州學院第十三屆大學生程式設計競賽D、H、I題解(後續補充)程式設計
- “位元組跳動杯”2018中國大學生程式設計競賽-女生專場程式設計
- 第二屆“重科杯”重慶科技大學程式設計競賽(同步賽)ptlks的題解(2024.5.18)程式設計
- 【學習筆記】計算幾何筆記
- M-災難預警-浙江農林大學第十九屆程式設計競賽暨天梯賽選拔賽程式設計
- 計算幾何:模板
- 計算幾何模板
- 程式設計天才“樓教主”—— 專訪兩屆“黑客杯”世界程式設計大賽季軍、清華大學博士生樓天城...程式設計黑客
- 湖南大學2020屆ACM新生賽 部分題解ACM
- 電子計算機類比賽的“武林秘籍”-電賽光電設計大賽計算機設計大賽嵌入式晶片與系統設計競賽,你要的都在這裡!計算機晶片
- 第九屆中國大學生程式設計競賽 深圳站(CCPC 2023 Shenzhen Site)/ The 2nd Universal Cup. Stage 25: Shenzhen程式設計
- 資料競賽:第四屆工業大資料競賽-虛擬測量大資料
- 【牛客訓練記錄】浙江機電職業技術大學第九屆程式設計競賽程式設計