ZOJ 3864 Quiz for EXO-L
2015-04-15 00:10
169 查看
题意:
给一些图片和矩阵, 要求出和矩阵匹配的图片。
思路:
机智的队友过的题。。。
首先,很明显大部分图片的黑白8联通块个数都是不同的,所以可以根据这个判断出大部分的图片。
不过很良心的样例给出了两个黑白联通块相同的情况, 这个时候求出两个图片的黑白比例,然后看比较靠近哪一个就取哪一个。。。
总之很神。。。
给一些图片和矩阵, 要求出和矩阵匹配的图片。
思路:
机智的队友过的题。。。
首先,很明显大部分图片的黑白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 ; 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 ; 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(); } }
相关文章推荐
- ZOJ 3864 Quiz for EXO-L
- 【搜索】 ZOJ 3864 Quiz for EXO-L BFS
- zoj 3864 Quiz for EXO-L(连通块 bfs)
- 机器学习中的神经网络Neural Networks for Machine Learning:Lecture 2 Quiz
- ZOJ_3568_Exchange for Cola(水题)
- zoj 1157 || poj 1087 A Plug for UNIX
- 子串数据ZOJ 1642 Match for Bonus
- zoj1642——Match for Bonus
- 机器学习中的神经网络Neural Networks for Machine Learning:Lecture 7 Quiz
- 机器学习中的神经网络Neural Networks for Machine Learning:Lecture 3 Quiz
- 机器学习中的神经网络Neural Networks for Machine Learning:Lecture 6 Quiz
- zoj 1642 Match for Bonus[dp,lcs]
- 机器学习中的神经网络Neural Networks for Machine Learning:Lecture 8 Quiz
- ZOJ 2278 Fight for Food
- zoj 1642 Match for Bonus(动态规划)
- ZOJ 1642 Match for Bonus (DP)
- Coursera Machine Learning 第六周 quiz Advice for Applying Machine Learning
- ZOJ 1642 Match for Bonus
- 机器学习中的神经网络Neural Networks for Machine Learning:Lecture 9 Quiz
- ZOJ 1642 Match for Bonus(dp)