题目: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. Java 8 VM GC Tunning Guide Charter 7-8-b

    第七章 并发gc Java 8提供两种并发gc,CMS和G1 Concurrent Mark Sweep (CMS) Collector This collector is for applicati ...

  2. Ui设计哪里有好的素材

    刚看到花瓣网,的确不错,以后得多逛逛了.(不喷广告,只留作笔记)

  3. Luence简单实现1

    初步认识Luence,简单按照官方文档做了个例子,大牛绕开,仅供小白路过参考.如有错误,欢迎指正批评. 建一个简单工程,并且加入这几个小奶瓶,如下图: 注:版本不同,可能对jdk的需求是不同的,这个需 ...

  4. PAT-乙级-1049. 数列的片段和(20)

    1049. 数列的片段和(20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 给定一个正数数列,我们可以从中截 ...

  5. 从String类看写C++ class需要注意的地方

    #include <iostream> #include <string.h> using namespace std; class String { char* m_data ...

  6. hdu 2717 Catch That Cow(BFS,剪枝)

    题目 #include<stdio.h> #include<string.h> #include<queue> #include<algorithm> ...

  7. [STL]单词转换

    如果单词转换文件的内容是: 'em         themcuz         becausegratz      grateful i             Inah        nopos ...

  8. struts2-2.3.4.1的struts-default.xml源码

    <?xml version="1.0" encoding="UTF-8" ?> <!-- /* * $Id: struts-default.x ...

  9. javascript加速运动

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  10. JavaEE5种常见的设计模式

    1.工厂模式:比如你写了个应用,里面用到了数据库的封装,你的应用可以今后需要在不同的数据库环境下运行,可能是oracle,db2,sql server等, 那么连接数据库的代码是不一样的,你用传统的方 ...