栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3864 Quiz for EXO

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3864 Quiz for EXO

#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 1000int 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;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();}}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号