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. 利用CSS3 animation绘制动态卡通人物,无需使用JS代码

    此外博主原创,转载请注明出处:谢谢~ 效果图: 其中云.风车.尾巴是动态的: 以下是代码: <!DOCTYPE html> <html lang="en"> ...

  5. CSS 3学习——animation动画

    以下内容根据官方文档翻译以及自己的理解整理. 1.  介绍 本方案介绍动画(animations).通过动画,开发者可以将CSS属性值的变化指定为一个随时间变化的关键帧(keyframes)的集合.在 ...

  6. 虾扯蛋:Android View动画 Animation不完全解析

    本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...

  7. 实现了一个百度首页的彩蛋——CSS3 Animation简介

    在百度搜索中有这样一个彩蛋:搜索“旋转”,“跳跃”,“反转”等词语,会出现相应的动画效果(搜索“反转”后的效果).查看源码可以发现,这些效果正是通过CSS3的animation属性实现的. 实现这个彩 ...

  8. 深入理解CSS3 Animation 帧动画

    CSS3我在5年之前就有用了,包括公司项目都一直在很前沿的技术. 最近在写慕课网的七夕主题,用了大量的CSS3动画,但是真的沉淀下来仔细的去深入CSS3动画的各个属性发现还是很深的,这里就写下关于帧动 ...

  9. Android动画效果之Property Animation进阶(属性动画)

    前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...

随机推荐

  1. struts2在result中使用el表达式碰到的问题

    <result name="success">/html/portlet/ext/trainingmanagement/download_file.jsp?path=$ ...

  2. 联系InfoSphere Streams和OpenMI时对水利模型联系的设计模式的一些考虑

    从<时序计算通用模型接口 OpenMI开发技术及应用>一书中的第一章的对接口要求描述,我想到InfoSphere streams的流数据处理模式刚好可以满足这种模型/数据之间对接的需求. ...

  3. Java判断字符串是否为空的三种方法

    方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低.1: if(s == null || s.equals("")); 方法二: 比较字符串长度, 效率高, 是我知道的最 ...

  4. EasyUI在MVC4中需要部分刷新页面时load()后页面变形问题!

    最近在使用MVC4与EasUI过程中遇到些容易导致界面变形的问题,纠结了很久,但其实当发现问题在哪里时,倒觉得最终还是自己对MVC4的概念没把握好,OK,show time.  本示例Contact ...

  5. git/github 笔记

    2016-1-9 创建github repos并提交修改 在[这里](https://github.com/new)创建一个repos, 进入终端,cd到一个目录下,这个目录用来放等下clone的工程 ...

  6. java后台开发- NOTE

    2015-1-6: IDEA servlet-api.jar idea从14升级到15后,发现 import javax.servlet.AsyncContext; 找不到,右击工程,open mod ...

  7. python request的运用

    requests是python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢?官方文档中是这样说明的: python的标准库urllib ...

  8. ARM Cortex-M3内核的巨大优势

    ARM Cortex-M3相比于ARM其他系列微控制器,具有以下优势或特点: 1. 三级流水线+分支预测 ARM Cortex-M3与ARM7内核一样,采用适合于微控制器应用的三级流水线,但增加了分支 ...

  9. 一个基于Qt的截屏程序

    最近有一个arm板上的程序需要重写用户手册,在网上找了许久,没找到合适的截屏工具.于是只好自己动手做一个了. 因为arm板上有已经有了Qt环境,于是想到用 Qt的QPixmap::grabWindow ...

  10. 顺序栈之C++实现

    顺序栈就是用顺序表(数组)实现的栈.其组织形式如下图所示: 下面介绍下我用C++实现的顺序栈,在VC6下调试通过.不足之处还请指正. 1.文件组织 2.ss.h栈类的声明及宏的定义 #ifndef _ ...