Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

奇技yin巧

Posted by zj123456 at 2016-05-24 21:57:07 on Problem 3774 and last updated at 2016-05-24 21:57:49
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const double inf=1e15;
struct P
{
    double x,y;
    P(){}
    P(double a,double b){x=a;y=b;}
    double D(){return x*x+y*y;}
    void Init(){scanf("%lf%lf",&x,&y);}
}POM,Hea,tmp[100],Mat[100][100];
struct Line{P p1,p2;}E,A[100][100];
int n,siz[100],num[100];
P operator-(P p1,P p2){return P(p1.x-p2.x,p1.y-p2.y);}
P operator+(P p1,P p2){return P(p1.x+p2.x,p1.y+p2.y);}
double operator/(P p1,P p2){return p1.x*p2.x+p1.y*p2.y;}
double operator*(P p1,P p2){return p1.x*p2.y-p2.x*p1.y;}
P Cross(Line l1,Line l2)
{
	double k1,k2,t;P p1;
	k1=(l2.p2-l1.p1)*(l1.p2-l1.p1);
	k2=(l1.p2-l1.p1)*(l2.p1-l1.p1);
	if((k1+k2)==0)return P(inf,inf);
	t=k2/(k1+k2);
	p1=P(l2.p1.x+t*(l2.p2.x-l2.p1.x),l2.p1.y+t*(l2.p2.y-l2.p1.y));
	if((p1.x<l2.p1.x&&p1.x<l2.p2.x)||(p1.x>l2.p1.x&&p1.x>l2.p2.x))p1=P(inf,inf);
	if((p1.y<l2.p1.y&&p1.y<l2.p2.y)||(p1.y>l2.p1.y&&p1.y>l2.p2.y))p1=P(inf,inf);
	if((p1-POM)/Hea<0)p1=P(inf,inf);
	return p1;
}
double Dis(P p1,P p2){return (p1-p2).D();}
void Judge(int x)
{
	int i;siz[x]=0;
	for(i=1;i<=num[x];i++)
	{
		P p1=Cross(E,A[x][i]);
		if(p1.x==inf&&p1.y==inf)continue;
		Mat[x][siz[x]=1]=p1;break;
	}
}
void Solve()
{
	int i,j,x,y;
	POM.Init();Hea.Init();
	memset(siz,0,sizeof(siz));memset(num,0,sizeof(num));
	E.p1=POM;E.p2=POM+Hea;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
		for(j=1;j<=num[i];j++)tmp[j].Init();
		tmp[num[i]+1]=tmp[1];
		for(j=1;j<=num[i];j++)A[i][j].p1=tmp[j],A[i][j].p2=tmp[j+1];
	}
	for(i=1;i<=n;i++)Judge(i);
	if(!siz[1]){printf("MISS\n");return;}
	double dis=Dis(POM,Mat[1][1]);
	for(i=2;i<=n;i++)
	  if(siz[i]&&Dis(POM,Mat[i][1])<dis){printf("MISS\n");return;}
	printf("HIT\n");
}
int main()
{
	while(scanf("%d",&n))
	 if(!n)break;
	 else Solve();
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator