POJ 1027 The Same Game 大暴消
来源:互联网 发布:优秀程序员简历模板 编辑:程序博客网 时间:2024/06/07 02:26
题目中给出了优先级 当四连块的size相同时 优先消左下角的
具体做题思路很简单
1、找出优先级最大的size最大的连通块 这一步显然是Floodfill求
2、比较鬼畜的输出答案...
3、消除连通块 同样可以Floodfill来求
4、更新整幅图 这也是本题最恶心的地方 一个特别繁琐的模拟...
Tips:鉴于本题输出实在太鬼畜...
我在这题上因为各种输出上的坑点WA了一下午...
不过我也费了好大劲搞到了官方的测试数据...这里共享给大家...
http://download.csdn.net/detail/sci_m3/9681676
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int dx[4] = {0, 1, 0, -1};const int dy[4] = {1, 0, -1, 0};char map[20][20];bool vis[20][20];int x, y, tmp; char c;inline void remove(int x, int y) { char c = map[x][y]; map[x][y] = '.'; for(int i = 0; i < 4; ++i) { int xx = x + dx[i], yy = y + dy[i]; if(xx >= 0 && yy >= 0 && xx < 10 && yy < 15 && map[xx][yy] == c) remove(xx, yy); }}inline void floodfill(int x, int y) { tmp++; vis[x][y] = true; for(int i = 0; i < 4; ++i) { int xx = x + dx[i], yy = y + dy[i]; if(xx >= 0 && yy >= 0 && xx < 10 && yy < 15 && !vis[xx][yy] && map[xx][yy] == map[x][y]) floodfill(xx, yy); }}inline int find(int &x, int &y, char &c) { int size = 0; memset(vis, false, sizeof(vis)); for(int j = 0; j < 15; ++j) for(int i = 0; i < 10; ++i) { if(!vis[i][j] && map[i][j] != '.') { tmp = 0; floodfill(i, j); if(tmp > size) { size = tmp; x = i; y = j; c = map[i][j]; } } } return size;}inline void f5() { for(int j = 0; j < 15; ++j) { int tmp = 0; for(int i = 0; i < 10; ++i) if(map[i][j] == '.') tmp++; for(int i = 0; i < 10 - tmp; ++i) while (map[i][j] == '.') { int k = i; while (k != 9) { swap(map[k][j], map[k + 1][j]); k++; } } } bool change[20]; int tmpx = 0; memset(change, false, sizeof(change)); for (int j = 0; j < 15; ++j) { int tmp = 0; for(int i = 0; i < 10; ++i) if(map[i][j] == '.') tmp++; if (tmp == 10) { change[j] = true; tmpx++; } } for (int j = 0; j < 15 - tmpx; ++j) while (change[j]) { int k = j; while (k != 14) { for(int i = 0; i < 10; ++i) swap(map[i][k], map[i][k + 1]); swap(change[k],change[k + 1]); k++; } }}int main() { int T; scanf("%d",&T); for(int cas = 1; cas <= T; ++cas) { for (int i = 9; i >= 0; --i) scanf("%s", map[i]); printf("Game %d:\n\n", cas); int leave = 150, step = 0, score = 0; for(;;) { int ans = find(x, y, c); if(ans <= 1) break; printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points.\n", ++step, x + 1, y + 1, ans, c, (ans - 2) * (ans - 2)); leave -= ans; score += (ans - 2) * (ans - 2); remove(x, y); f5(); } printf("Final score: %d, with %d balls remaining.\n\n",leave == 0 ? score + 1000 : score, leave); } return 0;}
0 0
- POJ 1027 The Same Game 大暴消
- poj 1027 The Same Game
- POJ 1027 The Same Game
- POJ 1027 The Same Game
- Poj 1027 The Same Game
- poj 1027 The Same Game
- POJ 1027--The Same Game
- POJ 1027The Same Game
- The Same Game POJ
- POJ 1027 The Same Game 模拟题
- POJ 1027 The Same Game BFS
- poj 1027 The Same Game(大模拟)
- poj 1027 The Same Game 模拟
- POJ 1027 The Same Game 笔记 未完成
- poj 1027.The Same Game
- POJ 1027 The Same Game棋盘游戏(模拟)
- POJ1027--The Same Game
- poj1027 The Same Game
- 校内互测 质数生成器 (数论)
- 软考总结
- 手把手教你做个人 app
- Linux常用终端快捷键Bash快捷键
- win7x64下的redis安装与使用(Redis-x64-3.0.501)
- POJ 1027 The Same Game 大暴消
- 【微信小程序】视图容器-swiper组件
- serlet
- odroid x2安装 Android 4.1 Beta-1.5
- 为什么我的DevC++不可以使用C++11的一些语法?
- 使用XMLHttpRequest实现AJAx
- Java实现Html转PDF
- React Native react-native-vector-icons 使用小记
- 凸包问题