2010 ACM-ICPC世界总决赛试题分析8-11

8

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define PB push_back
#define MP make_pair
const int MaxN=3009;
const double Pi=acos(-1.0);
int N,M;
int X[MaxN],Y[MaxN],H[MaxN],Level[MaxN];

bool NearSea[MaxN],vis[MaxN];
string Name[MaxN];
char ch[2];
map PointSet;
map,bool> EdgeSet;
vectorHeight,Lake;
vector> e[MaxN];
int Union_H[MaxN],Union_Level[MaxN],belong[MaxN],Union_num;
int Union_e[MaxN][MaxN];
bool Union_NearSea[MaxN];

void AddEdge(int a,int b)
{
	EdgeSet.insert(MP(MP(a,b),true));
	double deg=atan2(double(Y[b]-Y[a]),X[b]-X[a]);
	e[a].PB(MP(deg,b));
}

void FloodFill(int x,int p)
{
	if(vis[x])
		return;
	belong[x]=p;
	for(int i=0;i=Pi)
				NearSea[i]=true;
		if(e[i][0].first+2*Pi-e[i][e[i].size()-1].first>=Pi)
			NearSea[i]=true;
		for(int a=0;a

9

#include
#include
#include
const int MAXN=10;
const int fx[4][2]={1,0, 0,1, -1,0, 0,-1};
int n,m,t;
int x[5],y[5],c[5];
int map[MAXN][MAXN];
bool chk[MAXN][MAXN];
int ans;
bool b[4];
inline int abs(int x)
{
	return x<0?-x:x;
}

void init()
{
	memset(map,0,sizeof(map));
	t=n*m;
	for(int i=1;i<=3;++i)
	{
		scanf("%d %d",x+i,y+i);
		c[i]=i*t/4;
		map[x[i]][y[i]]=i;
	}
	x[4]=0;
	y[4]=1;
	c[4]=t;
	map[0][1]=4;
}

inline bool cut(int x,int y)
{
	int i,tx,ty;
	for(i=0;i<4;++i)
	{
		tx=x+fx[i][0];
		ty=y+fx[i][1];
		b[i]=((tx>=0)&&(tx=0)&&(ty0)
		return;
	if(dep==t)
	{
		++ans;
		return;
	}
	if(abs(x[c1]-x1)+abs(y[c1]-y1)>c[c1]-dep)
		return;
	int i,tx,ty;
	for(i=0;i<4;++i)
	{
		tx=x1+fx[i][0];
		ty=y1+fx[i][1];
		if((tx>=0)&&(tx=0)&&(ty

10

#include
#include
#include
#include
const int MAXN=20;
const int e2[]={0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288};
int n,x,y,t;
int a[MAXN];
int f[110][66000];
int g[66000];
int list[66000];
int next[66000];
inline int min(int a,int b)
{
	return a>1);++i)
	{
		for(j=list[i*y];j!=-1;j=next[j])
			if((j|s)==s)
			{
				if(get(min(i,y),i*y,j)&&get(min(x-i,y),area-i*y,s-j))
					return f[x][s]=1;
			}
	}
	for(i=1;i<=(y>>1);++i)
	{
		for(j=list[i*x];j!=-1;j=next[j])
			if((j|s)==s)
			{
				if(get(min(i,x),i*x,j)&&get(min(y-i,x),area-i*x,s-j))
					return f[x][s]=1;
			}
	}
	return f[x][s]=0;
}

void solve()
{
	if(t!=x*y)
	{
		printf("NO\n");
		return;
	}
	memset(g,0,sizeof(g));
	int i,j,k;
	for(i=0;i0)
				g[i]+=a[j];
	memset(list,0xff,sizeof(list));
	for(i=0;i

11
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define PB push_back
double fabs(double num)
{
	return num<0?-num:num;
}

double fmin(double num1,double num2)
{
	return num1<=num2?num1:num2;
}

double fmax(double num1,double num2)
{
	return num1>=num2?num1:num2;
}

double Sqr(double num)
{
	return num*num;
}

struct Point
{
	double X;
	double Y;
	double Z;
};

bool operator ==(Point A,Point B)
{
	return (A.X==B.X&&A.Y==B.Y&&A.Z==B.Z);
}

Point MakePoint(double X0,double Y0,double Z0)
{
	Point Ret;
	Ret.X=X0;
	Ret.Y=Y0;
	Ret.Z=Z0;
	return Ret;
}

Point operator + (Point A,Point B)
{
	return MakePoint(A.X+B.X,A.Y+B.Y,A.Z+B.Z);
}

Point operator - (Point A,Point B)
{
	return MakePoint(A.X-B.X,A.Y-B.Y,A.Z-B.Z);
}

double operator * (Point A,Point B)
{
	return A.X*B.X + A.Y*B.Y + A.Z*B.Z;
}

Point operator ^ (Point A,Point B)
{
	return MakePoint(A.Y*B.Z-A.Z*B.Y, A.Z*B.X-A.X*B.Z, A.X*B.Y-A.Y*B.X);
}

Point operator * (Point A,double x)
{
	return MakePoint(A.X*x,A.Y*x,A.Z*x);
}

Point operator / (Point A,double x)
{
	return MakePoint(A.X/x,A.Y/x,A.Z/x);
}

double Volume(Point A,Point B,Point C,Point D)
{
	return fabs(((B-A)^(C-A))*(D-A))/6.000;
}

double Distance(Point A,Point B)
{
	return sqrt(Sqr(A.X-B.X) + Sqr(A.Y-B.Y) + Sqr(A.Z-B.Z));
}

double Abs(Point p)
{
	return sqrt(Sqr(p.X)+Sqr(p.Y)+Sqr(p.Z));
}

vector Flat;
Point A,B,C,D,E,F,G,G_ABCD,G_ABCE,P[10];
double V_ABCD,V_ABCE;

void FindCentre()
{
	V_ABCD=Volume(A,B,C,D);
	V_ABCE=Volume(A,B,C,E);

	G_ABCD=(A+B+C+D)/4.000;
	G_ABCE=(A+B+C+E)/4.000;
	G=G_ABCD+((G_ABCE-G_ABCD)*V_ABCE)/(V_ABCD+V_ABCE);
}

bool SameSide(Point p1,Point p2,Point p3)
{
	Point Nor=(p2-p1)^(p3-p1);
	bool plus=false,minus=false;
	for(int i=1;i<=5;i++)
	{
		if(P[i]==p1||P[i]==p2||P[i]==p3)
			continue;
		double temp=(P[i]-p1)*Nor;
		if(temp<0)
			minus=true;
		else if(temp>0)
			plus=true;
	}
	if(plus&&minus)
		return false;
	Flat.clear();
	Flat.push_back(p1);
	Flat.push_back(p2);
	Flat.push_back(p3);
	for(int i=1;i<=5;i++)
	{
		if(P[i]==p1||P[i]==p2||P[i]==p3)
			continue;
		double temp=(P[i]-p1)*Nor;
		if(temp==0)
			Flat.push_back(P[i]);
	}
	return true;
}

Point Shadow(Point p,Point p1,Point p2,Point p3)
{
	Point Nor=(p2-p1)^(p3-p1);
	Point Nor0=(Nor*(Nor*(p-p1))/Abs(Nor)/Abs(Nor));
	return (p-Nor0);
}

double ShadowHeight(Point p,Point p1,Point p2,Point p3)
{
	Point Nor=(p2-p1)^(p3-p1);
	return fabs(Nor*(p-p1)/Abs(Nor));
}

bool SameSide(Point A,Point B,Point C,Point P)
{
	Point AB=B-A;
	Point AC=C-A;
	Point AP=P-A;

	Point v1=AB^AC;
	Point v2=AB^AP;

	return (v1*v2)>=0;
}

bool PointinTriangle(Point A,Point B,Point C,Point P)
{
	return SameSide(A,B,C,P)&&SameSide(B,C,A,P)&&SameSide(C,A,B,P);
}

bool PointInArea(Point p)
{
	for(int i=0;i0.000 && (A-B)*(P-B)>0.000)
		return sqrt(Sqr(Distance(A,P))-Sqr((B-A)*(P-A)/Abs((B-A))));
	return fmin(Distance(A,P),Distance(B,P));
}

bool Balance(Point p)
{
	if(!PointInArea(p))
		return false;
	for(int i=0;i0)
					plus=true;
				else if(Nor*(Flat[k]-P_i)<0)
					minus=true;
			}
			if(plus&&minus)
				continue;
			if(DistanceToLine(p,P_i,P_j)<0.2)
				return false;
		}
		return true;
}

void FindHull()
{
	double Min_Answer=2000.000,Max_Answer=0.000;
	P[1]=A;P[2]=B;P[3]=C;P[4]=D;P[5]=E;P[6]=F;
	for(int i=1;i<=5;i++)
		for(int j=i+1;j<=5;j++)
			for(int k=j+1;k<=5;k++)
			{
				if(SameSide(P[i],P[j],P[k]))
				{
					Point G0=Shadow(G,P[i],P[j],P[k]);
					if(Balance(G0))
					{
						Min_Answer=fmin(Min_Answer,ShadowHeight(F,P[i],P[j],P[k]));
						Max_Answer=fmax(Max_Answer,ShadowHeight(F,P[i],P[j],P[k]));
					}
				}
			}
	cout<


你可能感兴趣的:(2010 ACM-ICPC世界总决赛试题分析8-11)