题目: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 (几何)的更多相关文章

  1. Euclid(几何)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2831 题意:已知A,B,C,D,E,F的坐标, ...

  2. 关于Three.js基本几何形状之SphereGeometry球体学习

    一.有关球体SphereGeometry构造函数参数说明 <1>.SphereGeometry(radius, widthSegments, heightSegments, phiStar ...

  3. ZOJ1913 Euclid's Game (第一道简单的博弈题)

    题目描述: Euclid's Game Time Limit: 2 Seconds      Memory Limit: 65536 KB Two players, Stan and Ollie, p ...

  4. Euclid求最大公约数

    Euclid求最大公约数算法 #include <stdio.h> int gcd(int x,int y){ while(x!=y){ if(x>y) x=x-y; else y= ...

  5. 几何服务,cut功能测试

    关于几何服务 几何服务用于辅助应用程序执行各种几何计算,如缓冲区.简化.面积和长度计算以及投影.在 ArcGIS Server 管理器中启动几何服务之后,您才能够在应用程序开发过程中使用该服务. 问题 ...

  6. 几何服务,cut功能,输入要素target(修改后)内容。

    几何服务,cut功能测试,输入要素target(修改后)内容. {"displayFieldName":"","fieldAliases": ...

  7. 几何服务,cut功能,输入要素target(修改前)内容。

    几何服务,cut功能测试,输入要素target(修改前)内容. {"geometryType":"esriGeometryPolyline","geo ...

  8. HDU 1525 Euclid's Game 博弈

    Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. [poj2348]Euclid's Game(博弈论+gcd)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9033   Accepted: 3695 Des ...

随机推荐

  1. C# Windows - 创建控件

    VS提供了一个项目类型Windows Control Library,使用它可以创建自己的控件. 可以开发两种不同类型的自定义控件: 用户或组合控件:这种控件是根据现有控件的功能创建一个新控件.这类控 ...

  2. usb口外接了Com设备,U盘识别不了问题

    就如本题,当我usb口外接了Com设备时候,再插入U盘会出现识别不了的问题. 解决方法非常的简单,只要拨出这个com设备的usb就可以使用U盘了^_^

  3. CI_Autocomplete_2.0.php轻松实现Bebeans与Codeigniter的智能提示

    在你的NetBeans项目下建立一个CI_Autocomplete_2.0.php的文件,粘贴以下代码:(codeigniter太旧了,其实性能不行,应该没人更了,换了吧,别学这玩意了,坑人) < ...

  4. Hadoop集群中pig工具的安装过程记录

    在Hadoop环境中安装了pig工具,安装过程中碰到了一些问题,在此做一下记录:   主要安装流程参考:http://www.cnblogs.com/yanghuahui/p/3768270.html ...

  5. nenu contest2

    http://vjudge.net/vjudge/contest/view.action?cid=54562#overview H  B. Polygons http://codeforces.com ...

  6. epoll 知识总结

    poll/select/epoll 对比 http://www.cnblogs.com/apprentice89/p/3234677.html    ---有待继续学习 http://blog.chi ...

  7. jsp的常用指令有哪些(编译指令/动作指令整理)

    jsp的常用指令有哪些(编译指令/动作指令整理) JSP动作指令 JSP - JSP中的脚本.指令.动作和注释

  8. HDU4276 The Ghost Blows Light SPFA&&树dp

    题目的介绍以及思路完全参考了下面的博客:http://blog.csdn.net/acm_cxlove/article/details/7964739 做这道题主要是为了加强自己对SPFA的代码的训练 ...

  9. HDU 3397 Sequence operation (区间合并,操作比较多)

    费了我一天半的时间,到处debug,后来才发现,主要是建树的时候只在叶子节点对lazy1和lazy2进行初始化了,父节点都没初始化...晕. 具体见代码吧. #include <iostream ...

  10. java生成二维码的三个工具

    1.  使用SwetakeQRCode在Java项目中生成二维码 http://swetake.com/qr/ 下载地址 或着http://sourceforge.jp/projects/qrcode ...