这个月月初我们一行三人去湖南参加了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

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

即下面两个公式:

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

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define PI acos(-1.0)
using namespace std;
struct point
{
double x;
double y;
};
point readpoint(double x,double y)
{
point c;
c.x=x;
c.y=y;
return c;
}
point readinsertion(point t0,point t1,point k0,point k1)
{
point o;
double a0,b0,c0,a1,b1,c1,d;
a0=t0.y-t1.y;
b0=t1.x-t0.x;
c0=t0.x*t1.y-t1.x*t0.y;
a1=k0.y-k1.y;
b1=k1.x-k0.x;
c1=k0.x*k1.y-k1.x*k0.y;
d=a0*b1-a1*b0;
o.x=(b0*c1-b1*c0)/d;
o.y=(a1*c0-a0*c1)/d;
return o;
}
double ins(point a,point b)//求向量的模
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double dot(point a,point o,point b)//两向量坐标相乘
{
return (o.x-a.x)*(o.x-b.x)+(o.y-a.y)*(o.y-b.y);
}
double readAngle(point a,point o,point b)//向量点乘的逆运用
{
return acos(fabs(dot(a,o,b))/(ins(a,o)*ins(b,o)));
}
int main()
{
int t,a,b;
cin>>t;
while(t--)
{
cin>>a>>b;
double k1,k2,k3;
double r;
k1=tan((-a)*1.0/(/PI));//求两个直线方程的斜率
k2=tan((-b)*1.0/(/PI));
point a,b,c,d,e,o;
a=readpoint(,sqrt(3.0));//建立直角坐标系(A,B,C)
b=readpoint(,);
c=readpoint(,);
d=readpoint(,k1*);//在求一个该直线方程上的点
e=readpoint(,-*k2);
o=readinsertion(b,d,c,e);//求交点
r=readAngle(o,a,c)*/PI;//求夹角
printf("%.2lf\n",r);
}
return ;
}

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

  1. Python小白的数学建模课-A3.12 个新冠疫情数模竞赛赛题与点评

    新冠疫情深刻和全面地影响着社会和生活,已经成为数学建模竞赛的背景帝. 本文收集了与新冠疫情相关的的数学建模竞赛赛题,供大家参考,欢迎收藏关注. 『Python小白的数学建模课 @ Youcans』带你 ...

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

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...

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

    1195: OS Job Scheduling Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 106  Solved: 35 [id=1195&quo ...

  4. 江西财经大学第一届程序设计竞赛 G题 小Q的口袋校园

    链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

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

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 解题报告:中文题题意就不说了.还好数据不大,只有1000,枚举回文串的中心位置,然 ...

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

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1115 解题报告:输入n个字符串,让你求出可以用来区别这些字符串的最少的前缀总共有多少个字 ...

  7. 江西财经大学第一届程序设计竞赛 F题 解方程

    链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  8. 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘

    链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...

  9. ZOJ 4100 浙江省第16届大学生程序设计竞赛 A题 Vertices in the Pocket 线段树+并查集

    正赛的时候完全没看这个题,事后winterzz告诉我他想出来的解法. 首先题意是给出n个点,m次操作. 操作有一种是连接两个点,另一种是求此时再为这个图连k条边,最少和最多能有几个联通块. 最少的求法 ...

随机推荐

  1. 未加载Microsoft.SqlServer.management.sdk.sfc version......

    这个问题卡了我好久,于是决定记录下来,我这里缺失的是Microsoft.SqlServer.management.sdk.sfc version 12.0.0,当然你也可能后面是11开头的, 这个是由 ...

  2. _THROW 何解?

    在看/usr/include/........中.h头文件对函数接口的定义时,总是能看到在函数结尾加一个_THROW,一时不明白这是什么意思,而且对于有些POSIX和ISO C不承认或未明确的定义的函 ...

  3. S2S4H整合注意问题

    整合过程中出现问题记录: 1.The import javax.servlet.http.HttpServletRequest cannot be resolved 解决办法:在tomcat的lib目 ...

  4. Spring和ActiveMQ整合的完整实例

     Spring和ActiveMQ整合的完整实例 前言 这篇博文,我们基于Spring+JMS+ActiveMQ+Tomcat,做一个Spring4.1.0和ActiveMQ5.11.1整合实例,实现了 ...

  5. 使用SqlDependency监听MSSQL数据库表变化通知

    SqlDependency提供了这样一种机制,当被监测的数据库中的数据发生变化时,SqlDependency会自动触发OnChange事件来通知应用程序,从而达到让系统自动更新数据(或缓存)的目的. ...

  6. File.basename

    File.basename函数 返回filename中的最后一条斜线后面的部分.若给出了参数suffix且它和filename的尾部一致时,该方法会将其删除并返回结果. 例: p File.basen ...

  7. HDU - 1241 Oil Deposits 【DFS】

    题目链接 https://cn.vjudge.net/contest/65959#problem/L 题意 @表示油田 如果 @@是连在一起的 可以八个方向相连 那么它们就是 一块油田 要找出 一共有 ...

  8. C# 序列化反序列化 list<>

    public class XMLTest { [Test] public static void Test() { Name1 name = new Name1(); name.Id = " ...

  9. Dictionary and KeyValuePair关系

    简单一句话: Dictionary 是 由 KeyValuePair结构 组成的集合 The Dictionary<TKey, TValue>.Enumerator.Current pro ...

  10. 算法(Algorithms)第4版 练习 1.3.21

    方法实现: //1.3.21 /** * find if some node in the list has key as its item field * * @param list the lin ...