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

why

Posted by Akrusher at 2016-03-27 21:27:32 on Problem 1703
设了一个bool good,来判断这个编号的人有没有进行分组,如果两个人有一个没有在前面的D中出现,就输出NOt sure。然后再判断是不是在一个集合里,输出same or different。这样是WA的。
> 
> 看了网上的题解,先是判断是否在一个集合,是的话就是same,在判断x与y+N是不是一个集合的(就是他们是不是敌人),输出different,最后再输出Not sure。
> 
> 这样两个逻辑有什么差别?求大神解答。
/*
* Created:     2016年03月27日 20时02分22秒 星期日
* Author:      Akrusher
*
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define in(n) scanf("%d",&(n))
#define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
#define inll(n) scanf("%I64d",&(n))
#define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
#define inlld(n) scanf("%lld",&(n))
#define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
#define inf(n) scanf("%f",&(n))
#define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
#define inlf(n) scanf("%lf",&(n))
#define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
#define inc(str) scanf("%c",&(str))
#define ins(str) scanf("%s",(str))
#define out(x) printf("%d\n",(x))
#define out2(x1,x2) printf("%d %d\n",(x1),(x2))
#define outf(x) printf("%f\n",(x))
#define outlf(x) printf("%lf\n",(x))
#define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
#define outll(x) printf("%I64d\n",(x))
#define outlld(x) printf("%lld\n",(x))
#define outc(str) printf("%c\n",(str))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(X,Y) memset(X,Y,sizeof(X));
typedef vector<int> vec;
typedef long long ll;
typedef pair<int,int> P;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const bool AC=true;

int par[100005*2];
int ran[100005*2];
void init(int n){
 	rep(i,0,n){
 	par[i]=i;
 	ran[i]=0;
 	}
}
int find(int x){
	if(par[x]==x) return x;
	else
	return par[x]=find(par[x]);
}
void unite(int x,int y){
 	x=find(x);
 	y=find(y);
 	if(x==y) return ;
 	if(ran[x]<ran[y]){
 	par[x]=y;
 	}
 	else{
 	par[y]=x;
 	if(ran[x]==ran[y])
 	ran[x]++;
 	}
}
bool same(int x,int y){
return find(x)==find(y);
}
int main()
{
	int t,n,m,x,y,a,b;
	char s[6];
	in(t);
	while(t--){
	in2(n,m);
	init(2*n);
	rep(i,0,m){
	ins(s);
	in2(x,y);
	a=x-1;
	b=y-1;
	if(s[0]=='A'){
		if(n==2) printf("In different gangs.\n");//否则可能会wa
		else{
	    if(same(a,b)) printf("In the same gang.\n");
	    else if(same(a,b+n)) printf("In different gangs.\n");
		else printf("Not sure yet.\n");
		}
	}
	else if(s[0]=='D'){
	unite(a,b+n);
	unite(a+n,b);
	}
	}
  }
	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