这个月月初我们一行三人去湖南参加了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. 基于IAP和网口升级固件

    基于IAP和网口升级固件 一.      需求引入 现有嵌入式设备:基于ARM Cortex-M3处理器.带以太网通讯功能. 为减少设备维护成本节省宝贵的时间和金钱,须要设计网口升级固件功能. 本文描 ...

  2. Android 开发小工具之:Tools 属性 (转)

    Android 开发小工具之:Tools 属性 http://blog.chengyunfeng.com/?p=755#ixzz4apLZhfmi 今天来介绍一些 Android 开发过程中比较有用但 ...

  3. ABAP 弹出框 函数

    POPUP_GET_VALUES_USER_HELP 是一个和用户交互信息的函数,用户能够填写信息,并且我们还能够依据实际的需求对弹出框进行F1 F4 以及用户的需求进行增强.具体的实现能够參考系统标 ...

  4. String代码示例

    package lianxi; public class lianxi0112 { public static void main(String[] args) { // TODO 自动生成的方法存根 ...

  5. 【BZOJ1969】[Ahoi2005]LANE 航线规划 离线+树链剖分+线段树

    [BZOJ1969][Ahoi2005]LANE 航线规划 Description 对Samuel星球的探险已经取得了非常巨大的成就,于是科学家们将目光投向了Samuel星球所在的星系——一个巨大的由 ...

  6. python _、__和__xx__的区别(转)

    本位转载自:http://www.cnblogs.com/coder2012/p/4423356.html "_"单下划线 Python中不存在真正的私有方法.为了实现类似于c++ ...

  7. Entity Framework 4.1:多对多的关系

    这篇文章讨论多对多的关系. 让我们从最简单的例子开始.我们让 EF4.1 来推断表的映射.我在订单和雇员之间建模多对多的关系. )] publicstring CustomerName { get; ...

  8. Asp.Net Mvc: 浅析TempData机制

    一. Asp.Net Mvc中的TempData 在Asp.Net Mvc框架的ControllerBase中存在一个叫做TempData的Property,它的类型为TempDataDictiona ...

  9. new 和 make 均是用于分配内存

    the-way-to-go_ZH_CN/06.5.md at master · Unknwon/the-way-to-go_ZH_CN https://github.com/Unknwon/the-w ...

  10. Bootstrap——全局CSS样式

    1.栅格系统 containter:用于固定宽度并支持响应式布局的容器 container-fluid:用于100%宽度,占据全部视口(viewport)的容器 row:行,必须在container或 ...