湖南程序设计竞赛赛题总结 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
此题的求解角度的思路,用到了高中向量计算的常用方法,建立直角坐标系,利用两向量点乘的逆运用。
即下面两个公式:
解决此题也同时认识到了思路不能太局限,就像出题人所说求角就只去推角的关系,这样就输了,转个思路运用向量解决几何的问题是很重要的手段!!!
代码:
#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(计算几何)的更多相关文章
- Python小白的数学建模课-A3.12 个新冠疫情数模竞赛赛题与点评
新冠疫情深刻和全面地影响着社会和生活,已经成为数学建模竞赛的背景帝. 本文收集了与新冠疫情相关的的数学建模竞赛赛题,供大家参考,欢迎收藏关注. 『Python小白的数学建模课 @ Youcans』带你 ...
- angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...
- 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 ...
- 江西财经大学第一届程序设计竞赛 G题 小Q的口袋校园
链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- CSU 1328 近似回文词(2013湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 解题报告:中文题题意就不说了.还好数据不大,只有1000,枚举回文串的中心位置,然 ...
- 2012年湖南省程序设计竞赛E题 最短的名字
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1115 解题报告:输入n个字符串,让你求出可以用来区别这些字符串的最少的前缀总共有多少个字 ...
- 江西财经大学第一届程序设计竞赛 F题 解方程
链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘
链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...
- ZOJ 4100 浙江省第16届大学生程序设计竞赛 A题 Vertices in the Pocket 线段树+并查集
正赛的时候完全没看这个题,事后winterzz告诉我他想出来的解法. 首先题意是给出n个点,m次操作. 操作有一种是连接两个点,另一种是求此时再为这个图连k条边,最少和最多能有几个联通块. 最少的求法 ...
随机推荐
- linux SPI驱动——spi协议(一)
一:SPI简介以及应用 SPI, Serial Perripheral Interface, 串行外围设备接口, 是 Motorola 公司推出的一种同步串行接口技术. SPI 总线在物理上是通过接在 ...
- iOS:苹果企业证书通过网页分发安装app
本文转载至 http://blog.sina.com.cn/s/blog_6afb7d800101fa16.html 苹果的企业级证书发布的应用,是不用设备授权即可直接安装,并且不限设备上限.为了方便 ...
- UIScrollView奇葩不滑动
首先要说声尼玛,真奇葩,从来都没有遇到过这个问题,首先描述一下背景: 我是用XIB拖拽了一个UIScrollView在View上,然后设置了frame,在ViewDidLoad里面,设置了scroll ...
- spirng boot资料
这里有个srping boot 各种整合的资料 https://blog.csdn.net/Winter_chen001/article/details/80537829 SpringBoot入门总结 ...
- struts2的分页标签
1.准备tld文件 <?xml version="1.0" encoding="UTF-8" standalone="no"?> ...
- Vue:实践学习笔记(5)——Vue-Cli脚手架的使用
Vue:实践学习笔记(5)——Vue-Cli脚手架的使用 快速开始 项目配置 可视化配置 vue ui 命令配置 vue init webpack vue-demo(项目名) 运行测试 进入vue-d ...
- 《锋利的jQuery》打造个性网站整合
搜索框文字效果 网页换肤 导航效果 广告效果 添加超链接提示 产品横向滚动效果 光标滑动列表效果 产品详细页面效果(放大镜,遮罩,选项卡,评分等) 1.搜索框文字效果 <!DOCTYPE htm ...
- vuex原理笔记
本文总结自: https://tech.meituan.com/vuex-code-analysis.html, 将要点提炼为笔记,以便不时之需,安不忘危. 核心可分为两部分: 1.vue.use(V ...
- STS、Eclipse报java.lang.OutOfMemoryError: PermGen space 内存溢出
我使用的工具是STS, Eclipse同理: 打开如下界面: 左则选择项目启动使用的Tomcat-->在右侧面板Tab项中选择" Arguments":在VM argumen ...
- Spring Boot2.0之自定义参数
自定义参数,把不同环境的配置放到配置文件中去. 不同环境,如何区分配置文件信息,自定义配置文件信息 比如在 application.properties定义个参数 name=toov5 Spring ...