HDU 4793 2013 Changsha Regional Collision[简单的平面几何]

给出一个圆形奖牌的半径和一个圆形区域的半径,还有一枚硬币的半径,然后桌面是光滑的,给出圆硬币的速度(大小和方向,vx,vy)和坐标(圆区域和圆奖牌同心且心作为源点),问硬币在圆区域滑动的时间是多少(任何一部分在圆区域都算),硬币碰到圆奖牌会反弹,能量不变(速度不变)

第一次做平面几何题

看了题解,题解的板子真好用

大概来说有三种情况,如下图

第一种是进入圆区而不碰撞,查看h和Rm+r的关系

第二种是进入圆区且碰撞,查看h和Rm+r的关系

第三种是不进入圆区,查看方向向量和圆心到初始点向量这两个向量的夹角还有h和R+r的关系,而且应该先看向量,也可以先看R+r再讨论向量

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#define PI acos(-1.0)
#define maxn 100005
#define INF 0x7fffffff
#define eps 1e-8
using namespace std;
int cmp(double x) {
	if(fabs(x)<eps)
		return 0;
	if(x>0)
		return 1;
	return -1;
}
inline int sgn(double n) {
	return fabs(n)<eps?0:(n<0?-1:1);
}
inline double sqr(double x) {
	return x*x;
}
struct point{
	double x,y;
	point() {}
	point(double a,double b):x(a),y(b) {}
	void input() {
		scanf("%lf%lf",&x,&y);
	}
	friend point operator + (const point &a,const point &b) {
		return point(a.x+b.x,a.y+b.y);
	}
	friend point operator - (const point &a,const point &b) {
		return point(a.x-b.x,a.y-b.y);
	}
	friend bool operator == (const point &a,const point &b) {
		return cmp(a.x-b.x)==0 &&cmp(a.y-b.y)==0;
	}
	friend point operator * (const point &a,const double &b) {
		return point(a.x*b,a.y*b);
	}
	friend point operator * (const double &a,const point &b) {
		return point(a*b.x,a*b.y);
	}
	friend point operator / (const point &a,const double &b) {
		return point(a.x/b,a.y/b);
	}
	double norm() {
		return sqrt(sqr(x)+sqr(y));
	}//到原点距离
	void out () const {
		printf("%.2f %.2f",x,y);
	}
};
double det (const point &a,const point &b) {
	return a.x*b.y-a.y*b.x;
}//叉积
double dot (const point &a,const point &b) {
	return a.x*b.x+a.y*b.y;
}//点乘
double dist (const point &a,const point &b) {
	return (a-b).norm();
}//距离
point rotate_point(const point &p,double A) {
	double tx=p.x,ty=p.y;
	return point (tx*cos(A)-ty*sin(A),tx*sin(A)+ty*cos(A));
}//旋转,A是弧度
struct line {
	point a,b;
	line() {}
	line(point x,point y):a(x),b(y) {}
	point dire()const {
		return b-a;
	}//向量
	double len() {
		return dire().norm();
	}
};
bool parallel(line a,line b) {
	return !cmp(det(a.a-a.b,b.a-b.b));
}
bool line_make_point (line a,line b,point &res) {
	if(parallel(a,b))
		return false;
	double s1=det(a.a-b.a,b.b-b.a);
	double s2=det(a.b-b.a,b.b-b.a);
	res=(s1*a.b-s2*a.a)/(s1-s2);
	return true;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/home/rainto96/in.txt","r",stdin);
#endif
	double Rm,R,r,x,y,vx,vy;
	while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)){
                point s=point(x,y);
                point dir=point(vx,vy);
                if(dot(s,dir)>=0){
                        printf("0.000\n");
                        continue;
                }
                point tmp=point(vy,-vx);
                line l1=line(point(0,0),tmp);
                line l2=line(s,point(s.x+vx,s.y+vy));
                point ans;
                line_make_point(l1,l2,ans);
                double h=ans.norm();
                double h1=R+r;
                double h2=Rm+r;
                double speed=sqrt(vx*vx+vy*vy);
                if(h>=h1){
                        printf("0.000\n");
                        continue;
                }
                if(h>=h2){
                        double time=sqrt(h1*h1-h*h)/speed*2;
                        printf("%f\n",time);
                        continue;
                }else{
                        double time=sqrt(h1*h1-h*h)-sqrt(h2*h2-h*h);
                        time=time/speed*2;
                        printf("%f\n",time);
                        continue;
                }
	}
	return 0;
}
时间: 2024-08-03 12:38:34

HDU 4793 2013 Changsha Regional Collision[简单的平面几何]的相关文章

HDU 4793 Collision (2013长沙现场赛,简单计算几何)

Collision Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 685    Accepted Submission(s): 248Special Judge Problem Description There's a round medal fixed on an ideal smooth table, Fancy is tryin

HDU 4793 Collision + HDU 4798 Skycity 简单几何

HDU 4793 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793 题意:给一个以(0,0)为圆心半径为R的圆形区域,中间放着一个(0,0)为圆心半径为Rm的圆盘,在坐标(x,y)处(严格在圆形区域外)放着一枚半径为r的硬币,运动方向和速度为(vx,vy),在运动中碰到圆盘时,会按碰撞问题反弹(圆盘是固定不动的),问硬币会在圆形区域里呆多长时间(硬币只要有一点点在圆形区域里就记为硬币在圆形区域内). 思路:首先先计算出硬币在移动过程中如果不与圆盘

HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow, and Blue are in war. The map of battlefield is a tree, which means that there are N nodes and (N – 1) edges that connect all the nodes. Each country

HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys

hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有的连通分量只有一个点,当舍去该点时候,连通分量-1: 复习求割点的好题! #include<iostream> #include<cstdio> #include<vector> using namespace std; int n,m; vector<vector&

2013 Asia Regional Changchun

Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 1 #include<cstdio> 2 char op[1024]; 3 int main(){ 4 int t,n,m; 5 while(~scanf("%d",&t)){ 6 while(t--){ 7 scanf("%d%d%s",&n,&m,op); 8 for(int i=0;i<n;i++){ 9

HDU 1038[Biker&#39;s Trip Odometer]简单计算

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1038 题目大意:给轮子直径,转数,时间.要求输出走过的距离和时速(mile为单位) 关键思想:纯算 代码如下: #include <iostream> using namespace std; #define pi 3.1415927 int main(){ double d,r,t,l; int cnt=1; while(cin>>d>>r>>t&&a

[HDU 4082] Hou Yi&#39;s secret (简单计算几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082 题目大意: 给你n个点,问能最多构成多少个相似三角形. 用余弦定理,计算三个角度,然后暴力数有多少个,更新答案. 代码: 1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 #include <cstring> 5 #include <vector> 6 #includ

2013 Asia Regional Changchun C

Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 960    Accepted Submission(s): 344 Problem Description A crowd of little animals is visiting a mysterious laboratory