Windmill Animation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 147    Accepted Submission(s): 75

Problem Description
A windmill animation works as follows:

A two-dimensional set of points, no three of which lie on a line is chosen. Then one of the points is chosen (as the first pivot) and a line is drawn through the chosen point at some initial angle. The animation proceeds by rotating the line counter-clockwise about the pivot at a constant rate. When the line hits another of the points, that point becomes the new pivot point. In the two examples below, the points are (-1,1), (1,1), (0,0), (-1,-2) and (1,-2).

Example 1

In Example 1, the start point is point 1 and the line starts rotated 45 degrees from horizontal. When the line rotates to 90 degrees, point 4 is hit and becomes the new pivot. Then point 5 becomes the new pivot, then point 2 then point 1.

Example 2

In Example 2, the initial point is point 3 and the line starts horizontal. At 45 degrees, point 2 becomes the pivot, then at about 56 degrees, point 4 becomes the pivot. At about 63 degrees, point 3 becomes the pivot again, then point 5, point 1 and back to 3 as at the start.

Write a program, which takes as input the points of the set, the initial point and the initial line angle and outputs the sequence of pivot points.

 
Input
The first line of input contains a single integer P, (1<= P <= 1000), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists of multiple lines of input. The first line of each data set consists of four space- separated decimal integers followed by a single floating-point value. The first integer is the data set number. The second integer is the number of points M to follow (3 <= M <= 20). The third integer gives the number, s , of the pivot points to output (3 <= s <= 20) and the fourth integer gives the index, I, of the initial point (1 <= I <= M). The floating-point value is the angle, A, in degrees, that the initial line is rotated counter-clockwise from horizontal (0 <= A < 180).

The remaining M lines in the data set contain the coordinates of the set of points. Each line consists of an integer, the point.s index, I, and two floating-point values, the X and Y coordinates of the point respectively.

 
Output
For each data set there is a single line of output. It contains the data set number, followed by s space separated point indices (excluding the initial point index).

 
Sample Input
2
1 5 5 1 45
1 -1 1
2 1 1
3 0 0
4 -1 -2
5 1 -2
2 5 7 3 0
1 -1 1
2 1 1
3 0 0
4 -1 -2
5 1 -2
 
Sample Output
1 4 5 2 1 4
2 2 4 3 5 1 3 2
 
Source
 
方法:把题目中给出的任意两点连成的直线的斜率算出来并求得与x轴正向夹角并保存下来,以后每次找倾斜角角比当前直线倾斜角大的与其作差an[j][k]-a,如果倾斜角角比当前直线的小就+PI-当前的直线倾斜角an[j][k]+PI-a,这样找出最小的差值对应的点即为需要输出的点miny,然后更新旋转的那个店j,k1是与旋转点组成当前直线的另一个点,a是当前直线与x轴的夹角

#include<stdio.h>
#include<math.h> struct map
{
double x,y;
}s[50];
double an[50][50],PI=acos(-1.0);
int main()
{
int i,j,k,p,m,ss,no,I,minx,miny,k1;
double a,temp,mina;
scanf("%d",&p);
while(p--)
{
scanf("%d%d%d%d%lf",&no,&m,&ss,&I,&a);
a=a/180.0*PI;
for(i=1;i<=m;i++)
{
scanf("%d",&j);
scanf("%lf%lf",&s[j].x,&s[j].y);//这里写马虎了写成了%d,导致我耽误了好久来查错
}
printf("%d ",no);
for(i=1;i<m;i++)
{
for(j=i+1;j<=m;j++)
{
if(i!=j)
{
if(s[i].x-s[j].x)
{
temp=atan((s[i].y-s[j].y)/(s[i].x-s[j].x));
if(temp>=0)
an[i][j]=an[j][i]=temp;
else
an[i][j]=an[j][i]=temp+PI;
}
else
an[i][j]=an[j][i]=PI/2;
}
}
}
for(i=0,j=I,k1=I;i<ss;i++)//这里把j和k初始化为I,因为第一次直线上只有一个点
{
mina=PI;
for(k=1;k<=m;k++)
{
if(k!=j&&k!=k1)//保证不会取到直线上的两个点
{
if(an[j][k]>a)//角度比当前直线大
{
if(an[j][k]-a<mina)
{
mina=an[j][k]-a;
miny=k;
}
}
else//如果角度比当前直线小
{
if(an[j][k]+PI-a<mina)
{
mina=an[j][k]+PI-a;
miny=k;
}
}
}
}
if(i<ss-1)
printf("%d ",miny);
a=an[j][miny];//更新当前直线与x轴的夹角
k1=j;//更新组成当前直线的非旋转点
j=miny;
}
printf("%d\n",miny);
}
return 0;
}

hdu4491 Windmill Animation (几何)的更多相关文章

  1. hdu4491 Windmill Animation(计算几何)

    Windmill Animation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. hdu 4491 Windmill Animation

    A windmill animation works as follows: A two-dimensional set of points, no three of which lie on a l ...

  3. css3 animation实现风车转动

    项目中经常有用到动画效果,比如Loading.风车转动等等.最简单的办法是使用gif,但是gif在半透明背景下有白边,体验不友好,好在现在可以使用css3的anmiation来实现动画效果,极大的提升 ...

  4. iOS——Core Animation 知识摘抄(四)

    原文地址http://www.cocoachina.com/ios/20150106/10840.html 延迟解压 一旦图片文件被加载就必须要进行解码,解码过程是一个相当复杂的任务,需要消耗非常长的 ...

  5. iOS——Core Animation 知识摘抄(一)

    本文是对http://www.cocoachina.com/ios/20150104/10814.html文章的关键段落的摘抄,有需要的看原文 CALayer和UIView的关系: CALayer类在 ...

  6. Core Animation编程指南

    本文是<Core Animation Programming Guide>2013-01-28更新版本的译文.本文略去了原文中关于OS X平台上Core Animation相关内容.因为原 ...

  7. Qt-4.6动画Animation快速入门三字决

    Qt-4.6动画Animation快速入门三字决 Qt-4.6新增了Animation Framework(动画框架),让我们能够方便的写一些生动的程序.不必像以前的版本一样,所有的控件都枯燥的呆在伟 ...

  8. [iOS Animation]-CALayer 性能优化

    性能优化 代码应该运行的尽量快,而不是更快 - 理查德 在第一和第二部分,我们了解了Core Animation提供的关于绘制和动画的一些特性.Core Animation功能和性能都非常强大,但如果 ...

  9. [iOS Animation]-CALayer 定时器动画

    定时器的动画 我可以指导你,但是你必须按照我说的做. -- 骇客帝国 在第10章“缓冲”中,我们研究了CAMediaTimingFunction,它是一个通过控制动画缓冲来模拟物理效果例如加速或者减速 ...

随机推荐

  1. 浮动层固定兼容IE6 position:fixed的最佳解决方案

    第一种:css方法 有时候当我们需要把一个元素固定在页面的某个部位,一般都是用css中的“position:fixed;”方法来解决,但是IE6不支持fixed,所以今天分享一个兼容IE6的页面底部固 ...

  2. firefox 自写扩展改版,总结

    自己写的扩展,油猴功能,进一步改进,增加了许多操作.原来只是在13以下版本下面能用,主要是在13版本下面chrome代码和page下面代码能够直接互调,13版本以后就不可以了,最近考虑到新版Firef ...

  3. VPN服务器搭建好以后的安全防护

    之前讲过VPN的搭建过程,那么搭建完毕后,需要做哪些防护呢? 这里只说一下禁止VPN账户登录到服务器的设置,直接上图 找到权限分配后把VPN账号添加到拒绝本地登录的策略中,这样保障了VPN账户不能通过 ...

  4. C语言实践——学生信息管理

    这是本人做的第一个实践项目,用的知识都是书上有的,没有很多很复杂的知识 同时因为没有学习 C语言 图形方面的知识,所以界面做得很丑,暂时先这样吧 源文件: #include <stdio.h&g ...

  5. <meta http-equiv="Pragma" content="no-cache">

    <meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cac ...

  6. linux----命令替换

    0.命令替换.它的大概意思是.命令在脚本中只起一个站位符的作用:在命令运行时它会被命令自己的执行结果所替换. 1.使用格式: 1.$(command) 2.`command` 2.使用举例: 1.:打 ...

  7. Oracle EBS-SQL (SYS-11):查询系统已打的PATCH.sql

    select a.patch_name,         b.DRIVER_FILE_NAME,         c.language,         b.creation_datefrom app ...

  8. Ubuntu eclipse :An error has occurred. See the log file

    安装eclipse: sudo apt-get install eclipse-platform 调整java: sudo update-alternatives --config java 启动: ...

  9. elk之nginx

    elk之nginx: ignore_older => 86400,不处理一天以前的文件. zjtest7-frontend:/usr/local/logstash-2.3.4/config# c ...

  10. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(五)

    目的: 1. 了解PCI的基本知识,为完成watchdog的设备做准备. 准备知识: 简单的说,PCI 设备分3个空间. 配置空间,IO空间,内存地址空间. PCI设备厂家决定了外设是使用IO空间还是 ...