sdut 2831 Euclid (几何)
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2831
题意:给a, b, c, d, e, f 6个点
abgh是平行四边形。def是三角形。面积相等。
求点 g, h的坐标
思路:
1. DE*DF/2 = AH*AB; (向量DE叉乘向量DF,除以2, 等于 向量AH叉乘 AB)
2. AH = k AC; (向量AH 等于 k倍的向量AC)
将2式代入1式。就可以求得。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; struct point
{
double x, y;
}a, b, c, d, e, f, g, h;
double cross(point a, point b, point c)
{
return (fabs((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)));
}
int main()
{
double k;
while(cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y>>e.x>>e.y>>f.x>>f.y)
{
if(a.x==&&a.y==&&b.x==&&b.y==&&c.x==&&c.y==&&d.x==&&d.y==&&e.x==&&e.y==&&f.x==&&f.y==)
break;
k = cross(d, e, f)/;
k = k/cross(a, b, c); h.x = a.x+k*(c.x-a.x);
h.y = a.y+k*(c.y-a.y);
g.x = b.x+(h.x-a.x);
g.y = b.y+(h.y-a.y);
printf("%.3lf %.3lf %.3lf %.3lf\n", g.x, g.y, h.x, h.y);
}
return ;
}
再贴一个比赛时候的代码。
思想是求的 直线ac的方程,然后h满足方程, 把h.y用h.x 代替。带入条件。
这样做有三个缺点: 1、 把h.x带入方程, 由于先要换成向量的坐标表示, 还有相乘 的部分和替换的部分, 推导的过程很复杂。
2、算平行四边形的时候, 不知道叉积出来到 是正还是负, 带入方程,会错。
3、方程斜率不存在的时候,要另算, 麻烦。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std; struct node
{
double x, y;
} a, b, c, d, e, f, g, h;
double area(node d, node e, node f)
{
return (fabs((e.x-d.x)*(f.y-d.y)-(e.y-d.y)*(f.x-d.x))/);
}
int main()
{
double s_def;
while(cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y>>e.x>>e.y>>f.x>>f.y)
{
if(a.x==&&a.y==&&b.x==&&b.y==&&c.x==&&c.y==&&d.x==&&d.y==&&e.x==&&e.y==&&f.x==&&f.y==)
break;
s_def = area(d, e, f); double k , B;
if(a.x-c.x!=)
{
k = (double)((a.y-c.y)/(a.x-c.x));
B = (double)(a.y-k*a.x);
cout<<k<<" "<<B<<endl;
h.x = (double)((s_def+a.x*b.y+B*b.x-B*a.x-a.y*b.x)/(b.y-a.y-k*b.x+k*a.x)); cout<<h.x<<endl;
h.y = k*h.x+B;
}
else
{
h.x = a.x;
double ab;
ab = sqrt((b.x-a.x)*(b.x-a.x)-(b.y-a.y)*(b.y-a.y));
h.y = a.y + s_def/ab;
}
g.x = b.x + h.x - a.x;
g.y = b.y + h.y - a.y;
printf("%.3lf %.3lf %.3lf %.3lf\n", g.x, g.y, h.x, h.y);
}
return ;
}
sdut 2831 Euclid (几何)的更多相关文章
- Euclid(几何)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2831 题意:已知A,B,C,D,E,F的坐标, ...
- 关于Three.js基本几何形状之SphereGeometry球体学习
一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...
- ZOJ1913 Euclid's Game (第一道简单的博弈题)
题目描述: Euclid's Game Time Limit: 2 Seconds Memory Limit: 65536 KB Two players, Stan and Ollie, p ...
- Euclid求最大公约数
Euclid求最大公约数算法 #include <stdio.h> int gcd(int x,int y){ while(x!=y){ if(x>y) x=x-y; else y= ...
- 几何服务,cut功能测试
关于几何服务 几何服务用于辅助应用程序执行各种几何计算,如缓冲区.简化.面积和长度计算以及投影.在 ArcGIS Server 管理器中启动几何服务之后,您才能够在应用程序开发过程中使用该服务. 问题 ...
- 几何服务,cut功能,输入要素target(修改后)内容。
几何服务,cut功能测试,输入要素target(修改后)内容. {"displayFieldName":"","fieldAliases": ...
- 几何服务,cut功能,输入要素target(修改前)内容。
几何服务,cut功能测试,输入要素target(修改前)内容. {"geometryType":"esriGeometryPolyline","geo ...
- HDU 1525 Euclid's Game 博弈
Euclid's Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [poj2348]Euclid's Game(博弈论+gcd)
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9033 Accepted: 3695 Des ...
随机推荐
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料【转】
转自:机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一 ...
- 特征值分解,奇异值分解(SVD)
特征值分解和奇异值分解在机器学习领域都是属于满地可见的方法.两者有着很紧密的关系,我在接下来会谈到,特征值分解和奇异值分解的目的都是一样,就是提取出一个矩阵最重要的特征. 1. 特征值: 如果说一个向 ...
- 我今天坑了我们公司的IT程序猿。。。
今天在在公司邮箱发现了一个很神奇的事情! 同事的邮箱下面有个微博链接的签名. 光这个当然不是神器的,如果只是个图片加链接我也会,关键是他的这个链接和他的微博是实时交互的,他在微博上的状态会在链接里动态 ...
- lamada 表达式之神奇的groupby
少说话多干活 先定义一个测试用的实体,接下来会用字段Name进行分组的 public class TestToRun { public string Name { get; set; }//名称 pu ...
- 【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别
一直搞不明白两者的区别. 如果使用了SpringMVC,事实上,bean的配置完全可以在xxx-servlet.xml中进行配置.为什么需要applicationContext.xml?一定必须? 一 ...
- js冒泡事件的特例toggle无法实现阻止冒泡——slideDown()和slideUp()
一.问题 题目及答案展示:要求,点击题目,展开答案.如下: 展开前 展开后 最开始使用的toggle方法来实现 $(".content_problem").toggle( func ...
- iOS开发之数据存取2-CoreData后台查询数据
注意:本人所讲的后台查询必须在使用CoreData时选择存储类型为“SQLite”,因为二进制或者XML存储方式会在打开的时候直接读到内存中. 1.CoreData数据后台查询出现的情况 CoreDa ...
- 《head first java 》读书笔记(二)
Updated 2014/03/27 P402-P454 Updated 2014/04/03 P454- 世界三大首席管理器: border, flow, box borderLayout: 五个区 ...
- 翻译:用Javascript的Function构造器伪造上下文 by Ben Nadel
在我的jQuery模板标记语言(JTML)项目中,我需要一种方式将JTML模板编译到JS函数,这样它们就可以如期地在任何时候转换成新的HTML标记.但这是一个严峻的问题,因为JTML代码涉及非作用域( ...
- override equals in Java
equals() (javadoc) must define an equality relation (it must be reflexive, symmetric, and transitive ...