湖南程序设计竞赛赛题总结 XTU 1237 Magic Triangle(计算几何)

这个月月初我们一行三人去湖南参加了ccpc湖南程序设计比赛,虽然路途遥远,六月的湘潭天气燥热,不过在一起的努力之下,拿到了一块铜牌,也算没空手而归啦。不过通过比赛,还是发现我们的差距,希望这几个月自己努力思考,积极刷题,为九月份acm网络赛做准备!

言归正传说说这道题目,这也是这次比赛想到AC比较高的题目,不过我们还是没能完成,下面我就来总结一下此题的一些思路和方法。

Magic Triangle

Problem Description:

Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU.

Huangriq works in a big company in Guangzhou now, all things goes well but the mosquitos are too disturbing. Mosquito net and mosquito-repellent incense are useless for this mosquito city.

And finally he decides to use magic to kill them. He make a magic regular triangle as the picture shows. While the most proper position to launch magic is not always the center of circle. In order to make everything smoothly, Huangriq needs to get the value of  . And he already get two of them, can you help him to figure out the rest one?

Input

The first line contains a integer T(no more than 10000), which indicates the number of test cases. In the following T lines, each line contains two integers a and b () indicating the two angle Huangriq has already got.

Output

For each test case, output the rest angle‘s value with two digits after a decimal point in one line.

Sample Input

1
30 30

Sample Output

30.00

计算几何

求直线交点——叉积的应用

直线的一般方程为F(x) = ax + by + c = 0。

既然我们已经知道直线的两个点,假设为(x0,y0), (x1, y1),那么可以得到

a = y0 – y1, b = x1 – x0, c = x0y1 – x1y0

因此我们可以将两条直线分别表示为

F0(x) = a0*x + b0*y + c0 = 0, F1(x) = a1*x + b1*y + c1 = 0

那么两条直线的交点应该满足

a0*x + b0*y +c0 = a1*x + b1*y + c1

由此可推出

x = (b0*c1 – b1*c0)/D

y = (a1*c0 – a0*c1)/D

D = a0*b1 – a1*b0,(D为0时,表示两直线平行)

二者实际上就是连立方程组F0(x) = a0*x + b0*y + c0 = 0, F1(x) = a1*x + b1*y + c1 = 0的叉积应用

i     j     k

a0   b0   c0

a1   b1   c1

XTU 1237 Magic Triangle

此题的求解角度的思路,用到了高中向量计算的常用方法,建立直角坐标系,利用两向量点乘的逆运用。

即下面两个公式:

解决此题也同时认识到了思路不能太局限,就像出题人所说求角就只去推角的关系,这样就输了,转个思路运用向量解决几何的问题是很重要的手段!!!

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define PI acos(-1.0)
 6 using namespace std;
 7 struct point
 8 {
 9     double x;
10     double y;
11 };
12 point readpoint(double x,double y)
13 {
14     point c;
15     c.x=x;
16     c.y=y;
17     return c;
18 }
19 point readinsertion(point t0,point t1,point k0,point k1)
20 {
21     point o;
22     double a0,b0,c0,a1,b1,c1,d;
23     a0=t0.y-t1.y;
24     b0=t1.x-t0.x;
25     c0=t0.x*t1.y-t1.x*t0.y;
26     a1=k0.y-k1.y;
27     b1=k1.x-k0.x;
28     c1=k0.x*k1.y-k1.x*k0.y;
29     d=a0*b1-a1*b0;
30     o.x=(b0*c1-b1*c0)/d;
31     o.y=(a1*c0-a0*c1)/d;
32     return o;
33 }
34 double ins(point a,point b)//求向量的模
35 {
36     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
37 }
38 double dot(point a,point o,point b)//两向量坐标相乘
39 {
40     return (o.x-a.x)*(o.x-b.x)+(o.y-a.y)*(o.y-b.y);
41 }
42 double readAngle(point a,point o,point b)//向量点乘的逆运用
43 {
44     return acos(fabs(dot(a,o,b))/(ins(a,o)*ins(b,o)));
45 }
46 int main()
47 {
48     int t,a,b;
49     cin>>t;
50     while(t--)
51     {
52         cin>>a>>b;
53         double k1,k2,k3;
54         double r;
55         k1=tan((60-a)*1.0/(180/PI));//求两个直线方程的斜率
56         k2=tan((180-b)*1.0/(180/PI));
57         point a,b,c,d,e,o;
58         a=readpoint(1,sqrt(3.0));//建立直角坐标系(A,B,C)
59         b=readpoint(0,0);
60         c=readpoint(2,0);
61         d=readpoint(2,k1*2);//在求一个该直线方程上的点
62         e=readpoint(0,-2*k2);
63         o=readinsertion(b,d,c,e);//求交点
64         r=readAngle(o,a,c)*180/PI;//求夹角
65         printf("%.2lf\n",r);
66     }
67     return 0;
68 }
时间: 2024-08-13 10:44:19

湖南程序设计竞赛赛题总结 XTU 1237 Magic Triangle(计算几何)的相关文章

2012年湖南省程序设计竞赛E题 最短的名字

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1115 解题报告:输入n个字符串,让你求出可以用来区别这些字符串的最少的前缀总共有多少个字母.可以区别是指每个字符串都取一个自己的前缀,同时保证所有取的这些前缀没有完全相同. 这题用字典树可以做,就是输入的时候把所有的字符串都插入到字典树中,最后把所有被走过不止一次的节点的值都加起来,每个节点的值表示这个节点被走过多少次,然后如果碰到这个节点的值是1的时候总和加1,同时要退出,后面的就不

angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems called "Angry Birds" and "Angry Birds Again and Again" has been solved by many teams in the series of contest in 2011 Multi-University Tr

ZZUOJ-1195-(郑州大学第七届ACM大学生程序设计竞赛E题)

1195: OS Job Scheduling Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 106  Solved: 35 [Submit][Status][Web Board] Description OS(Operating System) is to help user solve the problem, such as run job(task).A multitasking OS is one that can simultaneo

ZZUOJ-1195-OS Job Scheduling(郑州大学第七届ACM大学生程序设计竞赛E题)

1195: OS Job Scheduling Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 106  Solved: 35 [Submit][Status][Web Board] Description OS(Operating System) is to help user solve the problem, such as run job(task).A multitasking OS is one that can simultaneo

2019-2020"新生赛"长沙理工大学程序设计竞赛E题合法括号

题目描述 众所周知,佳爷是集训队最强,他经常喜欢鄙视集训队最菜的PC,这天他又来了,他丢给PC一道题目: 给你一个字符串,该字符串只包含符号 '(’ 和 ‘)', ,我们称那些左右括号可以一一对应的括号字符串为完美字符串, 比如"()()()",  "((()))", "((()))()()", 都是完美字符串 而"((())", "()(", "((()))()(" 不是完美字符串.

浙江省第6届程序设计竞赛结题报告汇总 zoj3202-3212

zoj 3202 Second-price Auction 水题,不解释了,直接贴代码 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; struct node{ int x; int y; }; struct node number[105]; int cmp(struct node a,struct node b){

CSU 1328 近似回文词(2013湖南省程序设计竞赛A题)

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 解题报告:中文题题意就不说了.还好数据不大,只有1000,枚举回文串的中心位置,然后向两边扩展,当扩展到 k 大于要求的K的时候停止扩展,不断更新最长的长度跟开始位置最小.我先做了个预处理,先求出了a(S),然后用一个数组保存了a(S)中的字符在原来的字符串中对应的位置在哪,这样便于字符串比较,而且又可以在O(1)时间得到在原来串中的长度跟开始的位置. 1 #include<cs

ACM学习历程—SNNUOJ 1110 传输网络((并查集 &amp;&amp; 离线) || (线段树 &amp;&amp; 时间戳))(2015陕西省大学生程序设计竞赛D题)

Description Byteland国家的网络单向传输系统可以被看成是以首都 Bytetown为中心的有向树,一开始只有Bytetown建有基站,所有其他城市的信号都是从Bytetown传输过来的.现在他们开始在其他城市陆 续建立了新的基站,命令“C x“代表在城市x建立了一个新的基站,不会在同一个城市建立多个基站:城市编号为1到n,其中城市1就是首都Bytetown.在建立基站的过程中他们还 会询问某个城市的网络信号是从哪个城市传输过来的,命令”Q x“代表查询城市x的来源城市. Inpu

[简单思维题]Sequence(山东省第九届ACM大学生程序设计竞赛E题)

Problem Description We define an element a_iai? in a sequence "good", if and only if there exists a j(1\le j < i)j(1≤j<i) such that a_j < a_iaj?<ai?.Given a permutation pp of integers from 11 to nn. Remove an element from the permuta