ZOJ 3728 Collision
---恢复内容开始---
今天无事水一水,结果就看到这个水题了!
题意思是 有俩个区域如图

求在俩个圆之间的运动时间 给出 初始的开始点和速度的矢量式;而且这个点 不再俩个圆之间的区域,且碰到内测园会反弹:
在大大物实验的时候记得学过为了减少误差 和简易计算可以:把这个小圆看成质点,并把固定园的半径加上小圆的半径。
其实就是求 与俩个圆与射线的交点! 代码如下:()
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct point
{
double x,y;
point (double x=0,double y=0):x(x),y(y){}
};
typedef point Vector;
const double eps=1e-8;
int dcmp(double x)
{
if(fabs(x)<eps) return 0;
return x<0?-1:1;
}
Vector operator + (Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator - (Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator * (Vector a,double b){return Vector(a.x*b,a.y*b);} double det(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double lenth(Vector a){return sqrt(dot(a,a));}
struct line
{
point p;
Vector v;
double angle;
line(){}
line(point p,Vector v):p(p),v(v){}
bool operator <(const line &rht)const
{
return angle<rht.angle;
}
};
struct circle
{
point c;
double r;
circle(){c=point(0.0,0.0);}
circle(point c,double r):c(c),r(r){}
point Point(double rad)
{
return point(c.x+cos(rad)*r,c.y+sin(rad)*r);
}
};
int get_circle_intersection(line L,circle C,double &t1,double &t2)
{
t1=t2=0;
double a=L.v.x, b=L.p.x-C.c.x,c=L.v.y,d=L.p.y-C.c.y; double e=a*a+c*c,f=2*(a*b+c*d),g=b*b+d*d-C.r*C.r; double detle = f*f-4*e*g; if(dcmp(detle)<0) return 0;
if(dcmp(detle)==0) {t1=t2=-f/(2*e);return 1;}
t1=(-f-sqrt(detle)) /(2*e);
t2=(-f+sqrt(detle)) /(2*e);
if(dcmp(t1)<0 || dcmp(t2)<0) return 0;//按照速度的反方向才可以和圆相交
return 2;
}
int main()
{
double t1,t2;
double x1,x2;
line tmp;
circle tmp1;
circle tmp2;
double Rm, R, r;
while(~scanf("%lf %lf %lf %lf %lf %lf %lf",&Rm,&R,&r,&tmp.p.x,&tmp.p.y,&tmp.v.x,&tmp.v.y))
{
Rm+=r;R+=r;
tmp1.r=Rm;
tmp2.r=R;
int count1=get_circle_intersection(tmp,tmp1,t1,t2);
int count2=get_circle_intersection(tmp,tmp2,x1,x2);
if(count2==0)printf("0.00\n");
else
printf("%.3lf\n",fabs(x2-x1)-fabs(t1-t2));// 因为直线式点+向量(和速度一样)所以减法就可以了
}
return 0;
}
ZOJ 3728 Collision的更多相关文章
- 2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)
Collision Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge There's a round medal ...
- 简单几何(直线与圆的交点) ZOJ Collision 3728
题目传送门 题意:有两个一大一小的同心圆,圆心在原点,大圆外有一小圆,其圆心有一个速度(vx, vy),如果碰到了小圆会反弹,问该圆在大圆内运动的时间 分析:将圆外的小圆看成一个点,判断该直线与同心圆 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
随机推荐
- nodejs启动守护程序pm2
nodejs启动守护程序pm2 by 伍雪颖 做了个应用,server放阿里云,只是server总会自己断,后来写了个心跳程序,就是检測应用线程是否还在,不在就再启动, 这种方法好笨重啊,后来发现no ...
- 编程算法 - 萨鲁曼的军队(Saruman's Army) 代码(C)
萨鲁曼的军队(Saruman's Army) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 直线上有N个点, 每个点, 其距离为R以内的区域里 ...
- Android设计模式(二)--策略模式
1.定义: The Strategy Pattern defines a family of algorithms,encapsulates each one,and makes them inter ...
- PropertiesDemo
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configurat ...
- Music Studio项目心得--JNI实现C++调用JAVA
这个项目是我參加内蒙古挑战杯的比赛项目,因为时间关系,我没时间实现OpenOMR开源项目由JAVA全然向C++的转换,经过我半个多月的尝试,我将OpenOMR中的1/3的代码改写成C++,只是非常快我 ...
- Windows 10Bash命令
Windows 10预览版14316开启Bash命令支持 00x0 前言 4月7日凌晨,微软推送了最新的Windows 10一周年更新预览版14316,其中重要的是原生支持Linux Bash命令行支 ...
- windows server 2012显示桌面图标
windows server 2012安装后是没有桌面图标的,可以通过下面方式显示出来: 打开powershell rundll32.exe shell32.dll,Control_RunDLL de ...
- POJ 1753 位运算+枚举
题意: 给出4*4的棋盘,只有黑棋和白棋,问你最少几步可以使棋子的颜色一样. 游戏规则是:如果翻动一个棋子,则该棋子上下左右的棋子也会翻一面,棋子正反面颜色相反. 思路: 都是暴搜枚举. 第一种方法: ...
- 【翻译自mos文章】11gR2中的asm后台进程
11gR2中的asm后台进程 參考原文: ASM Background Processes in 11.2 (Doc ID 1641678.1) 适用于: Oracle Database - Ente ...
- shell 脚本之if、for、while语句
(1)if语句 root@ubuntu:/mnt/shared/shellbox/shellif# cat shellif.sh #!/bin/bash #推断字符串 if [ "$1&qu ...