HDU-1700 Points on Cycle
这题的俩种方法都是看别人的代码,方法可以学习学习,要多看看。。
几何题用到向量。。
Points on Cycle
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1294 Accepted Submission(s): 455
Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X.
when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
1.500 2.000
563.585 1.251
-280.709 -488.704 -282.876 487.453
//题意:一个以原点为中心的圆,告诉你圆上的一个点,求与另外的两个点组成的三角形的周长最长的两点作标。
//根据几何知识,知道圆内等边三角形的周长最长。所以题目转化为求已知一个点的圆内接等边三角形的另两点作标。
//思路:设P(x,y),一个方程是pow(x,2)+pow(y,2)=pow(r,2);另一个方程是根据向量知识,向量的夹角公式得到方程。
//因为圆心角夹角为120度,已知一个向量(即一个点作标),所以COS(2PI/3)=a*b/|a|*|b|;(a,b为向量);
//已知角和a向量,就可求b向量b(x,y).由方程组可求得(x,y);最后得到的是一元二次方程组,可得到两个解,即为两个点的作标。
//代码如下:
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
int main()
{
double x,y,x1,y1,x2,y2,cosx,a,b,c,r,delta;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&x,&y);
r=sqrt(x*x+y*y);
a=r*r;
b=r*r*y;
c=r*r*r*r/4-x*x*r*r;
delta=b*b-4*a*c;
y1=(-1*b-sqrt(delta))/(2*a);
y2=(-1*b+sqrt(delta))/(2*a);
if(x==0)
{
x1=-sqrt(r*r-y1*y1);
x2=sqrt(r*r-y2*y2);
}
else
{
x1=(-1*r*r/2-y*y1)/x;
x2=(-1*r*r/2-y*y2)/x;
}
printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
}
return 0;
}
/*已知一个以(0,0)为圆心的圆和圆上的一点(x0,y0)求圆上的另外两点(x1,y1,)(x2,y2),使得向量(x1,y1)(x2,y2)和(x0,y0)各个向量两两之间夹角为120度
此题主要用到向量的叉乘和点乘列出两个二元一次方程组
1.
(x0,y0)X (x1,y1) = sin(120)*R^2 (r为圆的半径)
(x0,y0) * (x1,y1) = cos(120)*R^2
结果为:
x1=b*x0-a*y0; a=sin120
y1=b*y0+a*x0; b=cos120;
2.
(x0,y0)X (x2,y2) = -sin(120)*R^2 (r为圆的半径)
(x0,y0) * (x2,y2) = cos(120)*R^2
注:题目假设向量(x1,y1)在向量(x0,y0)逆时针方向 故叉乘结果为正值
(x2,y2)于(x0,y0)的顺时针方向 故叉乘结果为负值*/
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,sinx,cosx,x0,y0,x1,y1,x2,y2;
int t;
a=sinx=sqrt(3.0)/2;
b=cosx=-0.5;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&x0,&y0);
x1=b*x0-a*y0;
y1=b*y0+a*x0;
x2=b*x0+a*y0;
y2=b*y0-a*x0;
if(y1<y2||((abs(y1-y2)<0.005)&&x1<x2))
{
printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
}
else
printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x1,y1);
}
return 0;
}
HDU-1700 Points on Cycle的更多相关文章
- hdu 1700 Points on Cycle(坐标旋转)
http://acm.hdu.edu.cn/showproblem.php?pid=1700 Points on Cycle Time Limit: 1000/1000 MS (Java/Others ...
- HDU 1700 Points on Cycle (坐标旋转)
题目链接:HDU 1700 Problem Description There is a cycle with its center on the origin. Now give you a poi ...
- HDU 1700 Points on Cycle (几何 向量旋转)
http://acm.hdu.edu.cn/showproblem.php?pid=1700 题目大意: 二维平面,一个圆的圆心在原点上.给定圆上的一点A,求另外两点B,C,B.C在圆上,并且三角形A ...
- HDU 1700 Points on Cycle(向量旋转)
题目链接 水题,卡了下下精度. #include <cstdio> #include <iostream> #include <cmath> using names ...
- hdu 1700 Points on Cycle 水几何
已知圆心(0,0)圆周上的一点,求圆周上另外两点使得三点构成等边三角形. 懒得推公式,直接用模板2圆(r1=dist,r2=sqrt(3)*dist)相交水过 #include<cstdio&g ...
- Points on Cycle (hdu1700,几何)
Points on Cycle Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu1700 Points on Cycle
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1700 题目: Points on Cycle Time Limit: 1000/1000 MS ...
- 暑假集训(2)第九弹 ----- Points on Cycle(hdu1700)
Points on Cycle Time Limit:1000MS Memory Limit:32768 ...
- L - Points on Cycle(旋转公式)
L - Points on Cycle Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- MVC 弹出提示框
第一种弹框成功后要刷新界面 [HttpPost] public ActionResult Add(Maticsoft.Model.Project.ProjectMoneyPlan model) { m ...
- 添加数据时候获取自增的ID
create database dbDemo go use dbDemo go create table tdstudent { id int primary key identity(1,1), n ...
- PHP学习心得(八)——运算符
运算符是可以通过给出的一或多个值(用编程行话来说,表达式)来产生另一个值(因而整个结构成为一个表达式)的东西.所以可以认为函数或任何会返回一个值(例如 print)的结构是运算符,而那些没有返回值的( ...
- (转载)c++builder/delphi中透明panel及透明窗口的实现方法_delphi教程
c++builder/delphi中透明panel及透明窗口的实现方法_delphi教程 可能大多数程序员会问:透明窗口,特别是透明Panel有什么应用价值呢?可别小看它们哦,下面我就来讲讲他们的巨大 ...
- Java基础中的一些注意点
1.在Java编程语言中,标识符是赋予变量.类或方法的名称.标识符可从一个字母.下划线(_)或美元符号($)开始,随后也可跟数字.标识符是大小写区别对待的并且未规定最大长度. 2.Java技术源程序采 ...
- 软件测试 -- Bug等级划分规范
1. Blocker级别——中断缺陷 客户端程序无响应,无法执行下一步操作. 2. Critical级别――临界缺陷,包括: 功能点缺失,客户端爆页. 3. Major级别——较严重缺陷,包括: 功能 ...
- Python Geospatial Development reading note(1)
chapter 1, Summary: In this chapter, we briefly introduced the Python programming language and the m ...
- C# zip/unzip with ICSharpCode.SharpZipLib
download ICSharpCode and add reference using System; using System.Collections.Generic; using System. ...
- 【单片机通信协议】CAN总线基础知识
CAN总线基础知识(一) 1.1 CAN总线是什么? CAN(Controller Area Network)是ISO国际标准化的串行通信协议.广泛应用于汽车.船舶等.具有已经被大家认可的高性能和可靠 ...
- tomcat 7 下添加 shared/lib 文件夹
你打开tomcat7\conf\catalina.properties文件再打开tomcat5的,看完后, 你就知道了 tomcat 5.5.35 # # List of comma-separate ...