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

Re:还是不明白下面大牛提到的相对偏移

Posted by lithum at 2009-07-24 16:32:51 on Problem 1182
In Reply To:Re:还是不明白下面大牛提到的相对偏移 Posted by:lithum at 2009-07-24 16:29:25
我把majiaN大牛的代码给补充成一个完整的程序了,代码如下,希望对你有帮助:-)

#include<iostream>
using namespace std;

int N,K;
int D,X,Y;
int lyn;

int p[100001];
int ch[50001];
int find(int k);
void check(int x,int y,int d);

int main()
{
	//freopen("input.txt","r",stdin);
	lyn=0;
	int i;
	cin>>N>>K;
	memset(ch,0,sizeof(ch));
	for(i=0;i<N+1;i++) p[i]=i;
	for(i=0;i<K;i++)
	{
		scanf("%d %d %d",&D,&X,&Y);
		check(X,Y,D-1);
	}
	cout<<lyn<<endl;
	return 0;
}

int find(int k)
{
	if (p[k]==k)
		return k;
	int t=find(p[k]);//t被赋值为k结点的最终根
	ch[k]=(ch[k]+ch[p[k]])%3; //这个向量关系需要发现 
	p[k]=t;
	return t;
}

void check(int x,int y,int d)
{
    int tp=find(x),tq=find(y);
    if(x>N||y>N) 
    {
        ++lyn;
        return;
    }
	if (tp==tq)
	{
		if ((ch[x]-ch[y]+3)%3!=d)//这个关系根据上面的可以自己用向量推 
		{
			++lyn;
		}
		return;
	}
	p[tp]=tq;
	ch[tp]=(ch[y]-ch[x]+d+6)%3;//这个同理 
}

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