popStar手机游戏机机对战程序
DFS算,五分钟如果答案没有更新,那个解一般来说就很优了。
#include <cstdio>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
using namespace std;
int const uu[4] = {1,-1,0,0};
int const vv[4] = {0,0,1,-1};
typedef long long ll;
int const inf = 0x3f3f3f3f;
ll const INF = 0x7fffffffffffffffll;
double eps = 1e-10;
double pi = acos(-1.0);
#define rep(i,s,n) for(int i=(s);i<=(n);++i)
#define rep2(i,s,n) for(int i=(s);i>=(n);--i)
#define mem(v,n) memset(v,(n),sizeof(v))
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
struct node{
int x,y;
}tempAns[205],Ans[205]; char FIRST[101][101];
bool VIS[101][101];
int bestScore;
int STEP; bool check(char mp[101][101],int x,int y){
rep(k,0,3){
int xx=x+uu[k], yy=y+vv[k];
if(xx>=1&&xx<=100 && yy>=1&&yy<=100 && mp[xx][yy]==mp[x][y]) return true;
}
return false;
}
int color1(char mp[101][101],bool vis[101][101],int x,int y){
vis[x][y]=true;
int res=1;
rep(k,0,3){
int xx=x+uu[k], yy=y+vv[k];
if(xx>=1&&xx<=100 && yy>=1&&yy<=100 && vis[xx][yy]==false && mp[xx][yy]==mp[x][y]) res+=color1(mp,vis,xx,yy);
}
mp[x][y]=0;
return res;
}
void proc1(char mp[101][101]){
rep(j,1,10) rep2(i,9,1){
int g=i,h=j;
while(g+1<=10 && mp[g+1][h]==0) ++g;
mp[g][h]=mp[i][j];
if(g!=i) mp[i][j]=0;
}
rep(j,2,10){
if(mp[10][j]==0) continue;
int k;
for(k=j-1;k>=1;--k) if(mp[10][k]!=0) break;
if(k+1<j){
rep(i,1,10){
mp[i][k+1]=mp[i][j];
mp[i][j]=0;
}
}
}
} void print(){
char ms[101][101];
bool vs[101][101]; mem(vs,false);
rep(i,1,10) rep(j,1,10) ms[i][j]=FIRST[i][j];
rep(i,1,10){
rep(j,1,10)
if(Ans[1].x==i&&Ans[1].y==j)
printf("#");
else{
if(ms[i][j]==0)
printf(" ");
else
printf("%d",ms[i][j]);
}
cout<<endl;
}
rep(i,1,STEP){
printf("step%d = (%d,%d)\n",i,Ans[i].x,Ans[i].y); cout<<endl<<endl;
color1(ms,vs,Ans[i].x,Ans[i].y);
proc1(ms);
if(i!=STEP){
rep(k,1,10){
rep(j,1,10)
if(Ans[i+1].x==k&&Ans[i+1].y==j)
printf("#");
else{
if(ms[k][j]==0)
printf(" ");
else
printf("%d",ms[k][j]);
}
cout<<endl;
}
}
}
} //mp[][]:current state step:current step score:current score
void dfs(char mp[101][101],bool vis[101][101],int tx,int ty,int step,int score){
//printf("step=%d score=%d click on (%d,%d) of last image.\n",step,score,tx,ty);
/*rep(i,1,10){
rep(j,1,10) if(mp[i][j]!=0) printf("%d ",mp[i][j]); else printf(" ");
cout<<endl;
}*/
tempAns[step].x=tx;
tempAns[step].y=ty;
rep(i,1,10) rep(j,1,10){
if(mp[i][j]==0) continue; //这个位置是空的,跳过
if(vis[i][j]) continue; //计算过,跳过
if(check(mp,i,j)==false){ //点击这个位置没法消去块
vis[i][j]=true;
continue;
}
char temp_mp[101][101];
bool temp_vis[101][101]; mem(temp_vis,false);
rep(i1,1,10) rep(j1,1,10) temp_mp[i1][j1]=mp[i1][j1];
int ts=color1(temp_mp,vis,i,j);
proc1(temp_mp);
dfs(temp_mp,temp_vis,i,j,step+1,score+5*ts*ts);
}
if(score>bestScore){
STEP=step;
rep(i,0,step) Ans[i]=tempAns[i];
bestScore=score;
cout<<"bestScore = "<<bestScore<<endl;
//print();
rep(i,1,step) printf("step%d = (%d,%d)\n",i,Ans[i].x,Ans[i].y); cout<<endl<<endl;
}
} void read(){
rep(i,0,10) rep(j,0,10) FIRST[i][j]=-1;
freopen("c:\\hello.in","r",stdin);
rep(i,1,10) rep(j,1,10) scanf("%d",&FIRST[i][j]);
fclose(stdin);
}
void init(){
bestScore=0;
mem(VIS,false);
}
int main(){
read();
init();
dfs(FIRST,VIS,-1,-1,0,0);
}
popStar手机游戏机机对战程序的更多相关文章
- unity手机游戏应用程序调试控制台Lunar Mobile Console - PRO 1.5.5
unity手机游戏应用程序调试控制台Lunar Mobile Console - PRO 1.5.5 High-performance Unity iOS/Android console built ...
- 手机游戏渠道SDK接入工具项目分享(二)万事开头难
一般接到任务后程序员们通常都开始着手进行技术调研了,但我这活是项目负责人.还有一大堆事情要先期准备,没人能帮忙. 一.人力配置 考虑的之前已经有一波人搞了大半年,但没有起色,先期也没有太大人力需求,所 ...
- Unity3D游戏开发初探—1.跨平台的游戏引擎让.NET程序员新生
一.Unity3D平台简介 Unity是由Unity Technologies开发的一个让轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的 ...
- 转:探秘腾讯Android手机游戏平台之不安装游戏APK直接启动法
前言 相信这样一个问题,大家都不会陌生, “有什么的方法可以使Android的程序APK不用安装,而能够直接启动”. 发现最后的结局都是不能实现这个美好的愿望,而腾讯Android手机游戏平台却又能实 ...
- 探秘腾讯Android手机游戏平台之不安装游戏APK直接启动法
前言相信这样一个问题,大家都不会陌生,“有什么的方法可以使Android的程序APK不用安装,而能够直接启动”.发现最后的结局都是不能实现这个美好的愿望,而腾讯Android手机游戏平台却又能实现这个 ...
- android手机游戏开发Cocos2d-x开发分享
我想现在应该没有人没有玩过手机游戏了吧,当然所有人都玩过,但不是所有人都知道怎么去开发手机游戏,因为许多人都感觉做开发是一件很困难的事儿,身边的朋友也对此感觉难度很大.但是,现在我可以告诉你,手机游戏 ...
- 斗牛app上架应用宝、牛牛手机游戏推广、百人牛牛app应用开发、棋牌游戏上传、手游APP优化
联系QQ:305-710439斗牛app上架应用宝.牛牛手机游戏推广.百人牛牛app应用开发.棋牌游戏上传.手游APP优化 iOS开发iPhone/iPad平台安卓手机软件开发机型覆盖范围 超过113 ...
- 创新手机游戏《3L》开发点滴(3)——道具、物品、装备表设计 V2(最终版)
我们正在开发一款新手游,里面有道具,之前也写了一篇博文记录了下我们的设计思路,但是国庆到了,于是我有了时间继续纠结这个问题. 其实我主要是在到底是用mysql还是mongodb上纠结.这个复杂.痛苦. ...
- Unity3D手机游戏开发
<Unity3D手机游戏开发> 基本信息 作者: 金玺曾 出版社:清华大学出版社 ISBN:9787302325550 上架时间:2013-8-7 出版日期:2013 年8月 开本:16开 ...
随机推荐
- php实现实例化类后自动进行错误以及异常处理(简易版)
<?php class App { public function __construct() { /* * ini_set 设置配置项 * display_errors 是否在页面显示错误信息 ...
- 事项同步事项编码(mt_code)长度超过数据库限制的varchar(32)线上问题
改下长度限制重新同步下,可以恢复正常!
- PHP 流行的框架
Aura Laravel Symphony Yii Zend php components Packagist 最好的组件: Awesome PHP https://www.yiiframework. ...
- jQuery has been removed
jQuery has been removed, 新的项目不要用jQuery了 这些问题都已经有了解决方案 * $()选择器, * $.ajax, * $dom.on("click" ...
- git 报错 gitThere is no tracking information for the current branch. Please specify which branch you w
新建本地分支后将本地分支推送到远程库, 使用git pull 或者 git push 的时候报错gitThere is no tracking information for the current ...
- Uncaught TypeError: upload is not a function at HTMLInputElement.onclick
js 中标签的id名称不能和方法名一样, <tr> <td><input type="button" id="login" val ...
- css布局宽度自适应
随着各种终端的不断涌现,网页中的元素适应不同的分辨率变得特别重要,根据经验,涉及到宽度自适应的一共有四种情况: 左端固定,右边自适应:右端固定,左边自适应:两端固定,中间自适应:中间固定,两端自适应. ...
- Ubuntu系统的开机全流程介绍及grub美化
目录 前言 Ubuntu开机经历的步骤 BIOS Boot Loader Kernel 配置 Grub 的个性化主题 /usr/share/grub/default/grub /etc/default ...
- 常见错误0xCCCCCCCCC 读取字符串的字符时出错及其引申。
问题描述在一个函数调用中,使用二级指针作为函数参数,传递一个字符串指针数组,但是在访问的时候,却出现了运行时错误,具体表现为"0xCCCCCCCC 读取字符串的字符时出错". 第一 ...
- T-SQL——数据透视和逆透视
目录 0. 测试数据集及说明 0.1 准备测试数据 0.2 对一维表和二维表理解 1. 透视转换 1.1 使用标准SQL进行数据透视 1.2 使用T-SQL中pivot函数进行数据透视 1.3 关于 ...