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

工作了,发现代码简单才是最重要的,贴个短的

Posted by sbtdkj1017 at 2010-10-08 15:36:10 on Problem 1066
#include<iostream>
#include<cstdlib>
using namespace std;
int geti(int x,int y)
{
	if(y==0)return x-1;
	if(x==100)return 99+y;
	if(y==100)return 299-x;
	return 399-y;
}
int main()
{
	int i=0,n,x0[30],y0[30],x1[30],y1[30],from,to,s[400]={};
	double x,y,k;
	for(cin>>n;i<n;i++)cin>>x0[i]>>y0[i]>>x1[i]>>y1[i];
	cin>>x>>y;
	for(i=0;i<n;i++)
	{
		k=(y0[i]-y1[i])/(x0[i]+1e-6-x1[i]);
		from=geti(x0[i],y0[i]);
		to=geti(x1[i],y1[i]);
		if((y-y1[i]>k*(x-x1[i]))-(x0[i]<x1[i]))swap(from,to);
		for(;from!=to;to=(to+399)%400)s[to]++;
	}
	for(i=0;i<400;i++)
		if(s[i]<n)n=s[i];
	cout<<"Number of doors = "<<n+1<<endl;
	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