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

384K,157/172ms(先登错號了2333,果然每次运行时间都是有误差的!)

Posted by KatrineYang at 2016-08-31 23:22:40 on Problem 1235
其实挺水的,逆向思维即可,从最后全部分开的时猴开始往前考虑。
布吉岛为啥这么点人AC~附代妈
#include <iostream>
#include <stdio.h>
using namespace std;

int N, M, K, L;
int n, m, k;

int blocks[9009][20];
int blockNum[9009];

int blockBH[9009];
int rep[9009];

int Abs(int a, int b){
	if(a-b >= 0) return a-b;
	return b-a;
}

void getNMK(int I){
	k = I/(M*N);
	m = (I%(M*N))/N;
	n = I%N;
}

bool isLT(int mon1, int mon2){
	for(int i = 0; i < blockNum[mon2]; i++){
		int tar = blocks[mon2][i];
		getNMK(tar);
		if(n>0 && blockBH[tar-1]==mon1) return 1;
		if(n<N-1 && blockBH[tar+1]==mon1) return 1;
		if(m>0 && blockBH[tar-N]==mon1) return 1;
		if(m<M-1 && blockBH[tar+N]==mon1) return 1;
		if(k>0 && blockBH[tar-M*N]==mon1) return 1;
		if(k<K-1 && blockBH[tar+M*N]==mon1) return 1;
	}
	return 0;
}

int getRep(int r){
	int tmp[9009];
	int cnt = 0;
	while(rep[r] != r){
		tmp[cnt] = r;
		cnt++;
		r = rep[r];
	}
	for(int i = 0; i < cnt; i++){
		rep[tmp[i]] = r;
	}
	return r;
}


int main() {
	int T;
	scanf("%d", &T);
	for(int ii = 0; ii < T; ii++){
		scanf("%d%d%d%d", &N, &M, &K, &L);
		for(int i = L-1; i >= 0; i--){
			scanf("%d", &blockNum[i]);
			for(int j = 0; j < blockNum[i]; j++){
				scanf("%d", &blocks[i][j]);
				blockBH[blocks[i][j]] = i;
			}
		}
		if(L <= 2){
			printf("0\n");
			continue;
		}
		int ans = 0;
		int ltfzgs = 1;
		rep[0] = 0;
		for(int i = 1; i < L-1; i++){
			int ltgs = 0;
			bool lt[9009] = {0};
			int ltList[9009];
			for(int j = 0; j < i; j++){
				int repj = getRep(j);
				if(lt[repj]) continue;
				if(isLT(i,j)) {
					lt[repj] = 1;
					ltList[ltgs] = repj;
					ltgs++;
				}
			}
			if(ltgs == 0){
				rep[i] = i;
				ltfzgs++;
			}
			else{
				rep[i] = ltList[0];
				for(int j = 1; j < ltgs; j++) rep[ltList[j]] = ltList[0];
				ltfzgs -= (ltgs-1);
			}
			if(ltfzgs > 1){
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	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