POJ 1027 The Same Game(模拟)
题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluster,同时cluster含有至少两个球),每次选择cluster中包含同色球最多的进行消除,每次消除完之后,上边的要往下移填满空的地方,一列上的球移动之前与之后相对位置不变,如果有空列,右边的列往左移动,每一列相对位置不变 。
思路 : 模拟。。。。。。不停的递归。。。。。
////POJ 1027
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;
int tmp,ans,tot,sum,k,xx,yy;
//tmp:cluster中同色球的个数,ans:每次要消除的球的个数,tot:当前图中剩的总的有颜色的球,sum,分值,k:步数,xx,yy指的是要消除的cluster是从该点开始的
bool v[][];
string a[];
char ch;
int dx[] = {,,,-};
int dy[] = {,,-,};
void remov(int x,int y)//递归消除掉同色的
{
char c = a[x][y];
a[x][y] = '';
for (int i = ; i < ; i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (xx >= && yy >= && xx < && yy < && a[xx][yy] == c)
remov(xx,yy);
}
}
void cluster(int x,int y)
{
tmp++;
v[x][y] = ;
for (int k = ; k < ; k++)
{
int xx = x + dx[k];
int yy = y + dy[k];
if (xx >= && yy >= && xx < && yy < && !v[xx][yy] && a[xx][yy]==a[x][y])
cluster(xx,yy);
}
}
int Find()
{
int maxx = ;
memset(v,,sizeof(v));
for (int j = ; j < ; j++)
for (int i = ; i < ; i++)
if (!v[i][j] && a[i][j]!='')
{
tmp = ;
cluster(i,j);
if (tmp > maxx)
{
maxx = tmp;
ch = a[xx = i][yy = j];
}
}
return maxx;
}
void fresh()
{
for (int j = ; j < ; j++)
{
int cnt = ;
for (int i = ; i < ; i++)
if (a[i][j] == '') cnt++;
for (int i = ; i < -cnt ; i++)
while (a[i][j]=='')//因为是倒着输入的,所以换不是往上换
{
int c = i;
while (c != )
{
swap(a[c][j],a[c+][j]);
c++;
}
}
}
int vis1[],tmpx = ;
memset(vis1,,sizeof(vis1));
for (int j = ; j < ; j++)//找空列
{
int cnt = ;
for (int i = ; i < ; i++)
if (a[i][j] == '') cnt++;
if (cnt == )
{
vis1[j] = ;
tmpx++;
}
}
for (int j = ; j < -tmpx ; j++)
while (vis1[j] == )
{
int c = j;
while (c != )
{
for (int i = ; i < ; i++)
swap(a[i][c],a[i][c+]);
swap(vis1[c],vis1[c+]);
c++;
}
}
}
int main()
{
int T ,casee = ;
scanf("%d",&T);
while(T--)
{
for (int i=; i>=; i--)
cin >> a[i];
printf("Game %d:\n\n",casee ++);
tot = ;
k = ;
sum = ;
while ()
{
ans = Find();
if (ans <= ) break;
printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points.\n",
k++,xx+,yy+,ans,ch,(ans-)*(ans-));
tot -= ans;
sum += (ans-)*(ans-);
remov(xx,yy);
fresh();
}
if (tot == ) sum += ;
printf("Final score: %d, with %d balls remaining.\n\n",sum,tot);
}
return ;
}
POJ 1027 The Same Game(模拟)的更多相关文章
- POJ 1027:The Same Game 较(chao)为(ji)复(ma)杂(fan)的模拟
The Same Game Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5168 Accepted: 1944 Des ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- POJ 3087 Shuffle'm Up (模拟+map)
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...
- POJ 1068 Parencodings【水模拟--数括号】
链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
- POJ 3672 Long Distance Racing (模拟)
题意:给定一串字符,u表示是上坡,d表示下坡,f表示平坦的,每个有不同的花费时间,问你从开始走,最远能走到. 析:直接模拟就好了,没什么可说的,就是记下时间时要记双倍的,因为要返回来的. 代码如下: ...
- poj 1696 Space Ant(模拟+叉积)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3840 Accepted: 2397 Descrip ...
随机推荐
- hdu 5112 A Curious Matt
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5112 A Curious Matt Description There is a curious ma ...
- 简述afinal 框架的基本用法
本文只是对afinal做简单的描述,基本和git上给的文档一样,大神绕道! FinalDB模块本文为涉及到 FinalActivity模块,FinalHttp模块,FinalBitmap模块 代码体 ...
- Windows Phone自定义控件 ProgressRing
前言 Windows Phone为开发者提供了很多原生控件,但在很多场景下我们需要对默认的功能或样式做一定的修改才能满足我们的需求,自定义控件应运而生.本文通过以自定义控件进度环(ProgressRi ...
- JVM规范小结
JVM规范组成: 1. 字节码(ByteCode): 以Class或Interface为基本单位, 具有固定结构. 2. 指令集(InstructionSet): 每个指令用一个字节表示, 最多256 ...
- SQL 执行顺序
SQL 是一种声明式语言,与其他语言相比它的最大特点是执行顺序-并非按照语法顺序来执行.因此很多程序猿看到SQL就头疼,我之前也是这样,后来看到一篇文章后豁然开朗-地址. 理解了SQL的执行顺序无疑对 ...
- [转]p2p端口映射工具 dog-tunnel
[转]p2p端口映射工具 dog-tunnel http://www.oschina.net/p/dog-tunnel 狗洞是一个高速的 P2P 端口映射工具,同时支持Socks5代理. 0.5版后开 ...
- MVC3+中 ViewBag、ViewData和TempData的使用和区别
在MVC3开始,视图数据可以通过ViewBag属性访问,在MVC2中则是使用ViewData.MVC3中保留了ViewData的使用.ViewBag 是动态类型(dynamic),ViewData 是 ...
- RTLviewer与TechnologyMapViewer的区别?
区别: 1.QUARTUS II 中往往要查看RTL Viewer,其实RTLview是编译后的结果,显示的图形都是调用标准单元的结果,这是和思维有关联的显示结果,跟工艺库,FPGA类型,都没有关系: ...
- Qt:禁止qDebug的输出
Qt:禁止qDebug的输出 在工程的.pro文件里加上以下编译批令即可: DEFINES += QT_NO_DEBUG_OUTPUT
- P3382: [Usaco2004 Open]Cave Cows 3 洞穴里的牛之三
首先,我们先确定,最长的曼哈顿距离只可能为 x1+y2-(x2+y2) 和 x1-y1-(x2-y2) 所以我们只需要维护四个值, 分别代表 max(x+y) ; max(x-y) ; min(x+y ...