hdu 4491 Windmill Animation
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.
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.
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
2 2 4 3 5 1 3 2
# include<iostream>
# include<cstring>
# include<cstdio>
# include<cmath>
# define pi (4.0*atan(1.0))
using namespace std;
struct
{
double x,y;
} a[25];
double mc[25][25];
int ca,m,s,st;
double du;
int ans[25];
void creat()
{
int i,j;
for (i=1;i<m;i++)
for (j=i+1;j<=m;j++)
{
double angle;
if (a[i].x==a[j].x)//横坐标相等的情况特判一下
{
mc[i][j]=pi/2;
mc[j][i]=mc[i][j];
continue;
}
angle=atan((a[i].y-a[j].y)/(a[i].x-a[j].x));
if (angle<0) angle=angle+pi;
mc[i][j]=angle;
if (mc[i][j]==pi) mc[i][j]=0;
mc[j][i]=mc[i][j];
}
}
void solve()
{
int i,j,pre=st;
du=du/180*pi;
for (i=1;i<=s;i++)
{
double min=-1;
int k=0;
for (j=1;j<=m;j++)
if (st!=j&&pre!=j)
{
double pp;
pp=mc[st][j]-du;
if (pp<0) pp=pp+pi;
if (min==-1||min>pp)
{
min=pp;
k=j;
}
}
pre=st; //更新之前点pre的值
du=mc[st][k]; //更新度数
st=k;//更新当前点的值
ans[i]=k;//记录每一步所到的点
}
}
int main()
{
int p;
scanf("%d",&p);
while (p--)
{
int i;
scanf("%d%d%d%d%lf",&ca,&m,&s,&st,&du);
for (i=1;i<=m;i++) scanf("%d%lf%lf",&i,&a[i].x,&a[i].y);
printf("%d ",ca);
creat(); //构造任意两点角度的二维矩阵
solve(); //模拟s次
for (i=1;i<=s;i++)
if (i<s) printf("%d ",ans[i]);
else printf("%d\n",ans[i]);
}
return 0;
}
/*
该题反映的问题:
1、# define pi 4.0*atan(1.0) 是将4.0*atan(1.0)整体替代pi的位置,
所以应该将pi后面的全部打上括号
2、低级错误,题目没看清楚,坐标的读入应该用实数
*/
hdu 4491 Windmill Animation的更多相关文章
- hdu4491 Windmill Animation (几何)
Windmill Animation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu4491 Windmill Animation(计算几何)
Windmill Animation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- css3 animation实现风车转动
项目中经常有用到动画效果,比如Loading.风车转动等等.最简单的办法是使用gif,但是gif在半透明背景下有白边,体验不友好,好在现在可以使用css3的anmiation来实现动画效果,极大的提升 ...
- 利用CSS3 animation绘制动态卡通人物,无需使用JS代码
此外博主原创,转载请注明出处:谢谢~ 效果图: 其中云.风车.尾巴是动态的: 以下是代码: <!DOCTYPE html> <html lang="en"> ...
- css3 animation 点亮灯光效果
<style> .wrap .bulb { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50% ...
- CSS 3学习——animation动画
以下内容根据官方文档翻译以及自己的理解整理. 1. 介绍 本方案介绍动画(animations).通过动画,开发者可以将CSS属性值的变化指定为一个随时间变化的关键帧(keyframes)的集合.在 ...
- 虾扯蛋:Android View动画 Animation不完全解析
本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...
- 实现了一个百度首页的彩蛋——CSS3 Animation简介
在百度搜索中有这样一个彩蛋:搜索“旋转”,“跳跃”,“反转”等词语,会出现相应的动画效果(搜索“反转”后的效果).查看源码可以发现,这些效果正是通过CSS3的animation属性实现的. 实现这个彩 ...
- 深入理解CSS3 Animation 帧动画
CSS3我在5年之前就有用了,包括公司项目都一直在很前沿的技术. 最近在写慕课网的七夕主题,用了大量的CSS3动画,但是真的沉淀下来仔细的去深入CSS3动画的各个属性发现还是很深的,这里就写下关于帧动 ...
随机推荐
- modernizr.js的介绍和使用
原文链接:https://www.cnblogs.com/-simon/p/5907053.html Modernizr帮助我们检测浏览器是否实现了某个feature,如果实现了那么开发人员就可以充分 ...
- 20162303石亚鑫 第十二周hash补充博客
要求 利用除留余数法为下列关键字集合的存储设计hash函数,并画出分别用开放寻址法和拉链法解决冲突得到的空间存储状态(散列因子取0.75) 关键字集合:85,75,57,60,65,(你的8位学号相加 ...
- play framework系列之打包war
概览 Play framwork 是我们一直在使用的框架,从刚开始的简单使用,乱起八糟的jar包引用,项目组成员之间的下载项目之后的引用问题等,遇到各种问题,我都一一解决,我将在这个系列中奉上解决方案 ...
- gearman学习笔记
<?php 搭建描述: . 在实际使用时应该是运行gearmand -d 的 server 一台. [要装gearmand,运行gearmand] . 处理worker的机器若干[要装gearm ...
- elasticsearch 亿级数据检索案例与原理
版权说明: 本文章版权归本人及博客园共同所有,转载请标明原文出处( https://www.cnblogs.com/mikevictor07/p/10006553.html ),以下内容为个人理解,仅 ...
- UVA 350 Pseudo-Random Numbers
Pseudo-Random Numbers Computers normally cannot generate really random numbers, but frequently are ...
- linux下mysql自动备份脚本
脚本放在 /home/user/mysql_backup.sh crontab # crontab -l # m h dom mon dow command 28 16 * * * /home/ ...
- 使用注册表优化终端、编辑器的中英字体混合显示,如「Consolas + 雅黑」「Monaco + 雅黑」
在终端.cmd.编辑器中偶尔会有中文字符出现,Windows下默认的点阵字体「宋体」和等宽英文字符放在一起非常违和.一个解决方法是下载混合字体,比如「Consolas + YAHEI hybrid」, ...
- High Voltage Boost Supply
http://learn.adafruit.com/ice-tube-clock-kit/design Tubes such as VFDs, Nixies, Decatrons, etc requi ...
- SHP文件合并
ArcGIS中合并SHP文件是一个常用的操作,下面简要讲解一下如何合并. 使用ArcGIS Tool Box(ArcGIS工具箱)中的Data Management Tools-->Genera ...