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

官方数据都过了还死活WA,晒晒我的代码,线段树做的,哪位大侠指教一二~

Posted by Rieman at 2011-02-11 21:36:49 on Problem 2528
#include <iostream>
//#include <windows.h>
using namespace std;
const int inf=(int)1e7+1;
struct poster
{
  int left,right,a,b,size,dad;bool cov;
}post[inf/10],null;
int p;
int search(int a,int b,int k,int f,int fat)
{
  int fa,fb,fc,mi;
  if(post[k].cov) return 0;
  if(k==0)
  {
	post[p]=null,fa=post[fat].a,fb=post[fat].b,post[p].dad=fat,fc=(fa+fb)/2;
	if(f)
	  post[p].a=fa,post[p].b=fc,post[fat].left=p;
	else
	  post[p].a=fc+1,post[p].b=fb,post[fat].right=p;
	k=p,p++;
  }
  if(a==post[k].a&&b==post[k].b)
  {
	if(post[k].cov) return 0;
	post[k].cov=1;
	for(fa=post[k].dad;;fa=post[fa].dad)
	  if(post[post[fa].left].cov&&post[post[fa].right].cov)
		post[fa].cov=1;
	  else
		break;
	if(post[k].size==0) post[k].size=1;
	return 1;
  }
  mi=(post[k].a+post[k].b)/2;
  if(b<=mi)
	post[k].size+=(fa=search(a,b,post[k].left,1,k));
  else if(a>mi)
	post[k].size+=(fa=search(a,b,post[k].right,0,k));
  else
  {
	fc=search(a,mi,post[k].left,1,k),fb=search(mi+1,b,post[k].right,0,k);
	post[k].size+=(fa=fc||fb);
  }
  return fa;
}
int main()
{
  int e,n,i,poa[10001],pob[10001];
  //FILE *in=fopen("E:\\Rieman's Files\\ACM\\input.txt","r"),*out=fopen("E:\\Rieman's Files\\ACM\\output.txt","w");
  scanf("%d",&e);
  //int t=GetTickCount();
  while(e--)
  {
	scanf("%d",&n);
	for(i=n;i>0;i--)
	  scanf("%d%d",poa+i,pob+i);
	post[1]=null,post[1].a=1,post[1].b=inf;
	for(p=2,i=1;i<n+1;i++)
	  search(poa[i],pob[i],1,0,0);
	cout<<post[1].size<<endl;
  }
  //printf("%d ms\n",GetTickCount()-t);
  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