这个月月初我们一行三人去湖南参加了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. linux 上操作常用的命苦与出错的地方

    帮助信息 ./configure -help|grep mysql 出错提示安装libxml2 tar -zxvf libxml2xxxx.tar cd libxml2xxx ./configure ...

  2. 图像处理之基础---二维卷积c实现

    http://wenku.baidu.com/link?url=4RzdmvP9sdaaUbnVEW4OyBD-g67wIOiJjKFF3Le_bu7hIiBS7I6hMcDmCXrQwsHvrsPv ...

  3. WCF基础之配置服务

    在WCF应用编程中配置服务是其主要部分. 配置可以定义和自定义如何向客户端公开服务,包括服务地址,发送和接受消息的传输和编码,以及服务的安全类型. 服务的配置有两种:编码和使用config文件,大多数 ...

  4. 九度OJ 1146:Flipping Pancake(翻饼子) (递归、游戏)

    时间限制:1 秒 内存限制:32 兆 特殊判题:是 提交:265 解决:116 题目描述: We start with a stack n of pancakes of distinct sizes. ...

  5. Ruby操作数据库基本步骤

    1.rails g model university name:string 2.model has_many :colleges belongs_to :university has_one :us ...

  6. Django--组件-用户认证Auth(auth_user增加字段)

    引入 :  from django.db import models from django.contrib.auth.models import AbstractBaseUser 源码 :  fro ...

  7. Quartz Job scheduling 基础实现代码

    Quartz 集成在 SpringBoot 中分为 config.task.utils.controller 和 MVC 的三层即 controller.service.dao 和 entity. c ...

  8. Eureka 集群

    集群搭建是在单节点基础上做的 单节点注册中心搭建-->https://www.cnblogs.com/chenglc/p/9561295.html 在单节点的基础上修改配置文件 bootstra ...

  9. BFC和haslayout(IE6-7)(待总结。。。)

    支持BFC的浏览器(IE8+,firefox,chrome,safari) Block Formatting Context(块格式化上下文)是W3C CSS2.1规范中的一个慨念,在CSS3中被修改 ...

  10. Object.create用法

    用法: Object.create(object, [,propertiesObject]) 创建一个新对象,继承object的属性,可添加propertiesObject添加属性,并对属性作出详细解 ...