ZOJ 3864 Quiz for EXO-L

题意:

给一些图片和矩阵, 要求出和矩阵匹配的图片。

思路:

机智的队友过的题。。。

首先,很明显大部分图片的黑白8联通块个数都是不同的,所以可以根据这个判断出大部分的图片。

不过很良心的样例给出了两个黑白联通块相同的情况, 这个时候求出两个图片的黑白比例,然后看比较靠近哪一个就取哪一个。。。


总之很神。。。

#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define N ( 1000 + 10 )
#define M ( 400000 + 10 )
#define LL long long
#define inf 0x3f3f3f3f
#define lson id << 1, l, m
#define rson id << 1 | 1, m + 1, r
#define mod 1000


int a[N][N];
int cx, cy;
int n;
void build( int x, int k ) {
	while( x-- ) {
		a[cx][cy] = k;
		cy++;
		if( cy == n ) ++cx, cy = 0;
	}
}


bool out ( int x, int y ) {
	if( x < 0 || x >= n || y < 0 || y >= n ) return 1;
	return 0;
}

int dx[] = { -1, 1, 0, 0, 1, 1, -1, -1 };
int dy[] = { 0, 0, -1, 1, -1, 1, 1, -1 };
bool vis[N][N];
int num[2][1002000];
int wcnt, bcnt;
void dfs ( int x, int y, int k ) {
	vis[x][y] = 1;
	if( k == 0 ) {
		++num[0][bcnt];
	}
	else ++num[1][wcnt];
	for( int i = 0; i < 8; ++i ) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if( out( nx, ny ) || vis[nx][ny] || a[nx][ny] != k ) continue;
		dfs( nx, ny, k );
	}
}
void bfs(int x, int y, int k) {
    queue<int> q;
    q.push(x), q.push(y);
    vis[x][y] = 1;
    while(!q.empty()) {
        int ix = q.front(); q.pop();
        int iy = q.front(); q.pop();
        if(k == 0) ++num[0][bcnt];
        else ++num[1][wcnt];

        for(int i = 0; i < 8; ++i) {
            int nx = ix + dx[i];
            int ny = iy + dy[i];
            if(out(nx, ny) || vis[nx][ny] || a[nx][ny] != k) continue;
            vis[nx][ny] = 1;
            q.push(nx), q.push(ny);
        }
    }
}
void print ( ) {
	if( bcnt == 9 ) {
		puts("Baekhyun");
	}
	if( bcnt == 5 ) {
		if( wcnt == 1 ) {
			puts("Chanyeol");
		}
		if( wcnt == 8 ) {
			puts("Luhan");
		}
		if( wcnt == 2 ) {
			double w = num[1][1] * 1.0 / num[1][2];
			if( w > 12.5 ) {
				puts("Xiumin");
			}
			else puts("Sehun");
		}
	}
	if( bcnt == 1 ) {
		if( wcnt == 3 ) {
			puts("Chen");
		}
		if( wcnt == 2 ) {
			puts("D.O");
		}
	}
	if( bcnt == 2 ) {
		if( wcnt == 13 ) {
			puts("Kai");
		}
		if( wcnt == 8 ) {
			puts("Suho");
		}
		if( wcnt == 4 ) {
			puts("Tao");
		}
	}
	if( bcnt == 3 ) {
		puts("Kris");
	}
	if( bcnt == 6 ) {
		puts("Lay");
	}
}
int main ()  {
	int T;
	//freopen( "tt.txt", "r", stdin );
	scanf("%d", &T );
	while( T-- ) {
		int m;
		int x;
		scanf("%d%d", &n, &m );
		cx = 0, cy = 0;
		int k = 1;
		while( m-- ) {
			int x;
			scanf("%d", &x );
			build( x , k);
			k ^= 1;
		}
		wcnt = 0, bcnt = 0;
		memset( vis, 0, sizeof( vis ) );
		memset( num, 0, sizeof( num ) );
		for( int i = 0; i < n; ++i ) {
			for( int j = 0; j < n; ++j ) {
				if( !vis[i][j] ) {
					if( a[i][j] == 1 ) {
						++wcnt;
						bfs(i, j, 1);
					}
					else {
						++bcnt;
						bfs(i, j, 0);
					}
				}
			}
		}

		print();
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值