POJ 1027 The Same Game 模拟题
来源:互联网 发布:php中文网站模板下载 编辑:程序博客网 时间:2024/06/14 15:30
一道模拟题目,思路一点不难,不过想要快速A掉,对于现在的我而言,还做不到。
没什么难的,就是麻烦一点,一个模拟题,做的有点恶心了。。。。。。
http://poj.org/problem?id=1027
代码贴上
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#define PI acos(-1.0)#define max(a,b) (a)>(b)? (a):(b)#define min(a,b) (a)>(b)? (b):(a)char map[15][20];int vis[15][20],ttt,score;struct node{ int x,y;} dui[400];int mov[4][2]= {1,0,-1,0,0,1,0,-1};int bfs(int x,int y,int tt){ int i,j; struct node now,next; int head,tail; head=tail=0; vis[x][y]=tt; dui[tail].x=x; dui[tail++].y=y; while(head<tail) { now=dui[head++]; for(i=0; i<4; i++) { next.x=now.x+mov[i][0]; next.y=now.y+mov[i][1]; if(next.x<0 || next.y<0 || next.x>=10 || next.y>=15) continue; if(map[next.x][next.y]!=map[now.x][now.y]) continue; if(vis[next.x][next.y]) continue; vis[next.x][next.y]=tt; dui[tail++]=next; } } return tail;}void remov(int x,int y){ int i,j,k; char ch; int su=0; int xx,yy,flag=0; for(i=0; i<15; i++) { for(j=0; j<10; j++) { if(vis[j][i]==x) { if(!flag) { xx=j; yy=i; flag=1; ch=map[j][i]; } map[j][i]=' '; } } } printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points. \n",++ttt,xx+1,yy+1,y,ch,(y-2)*(y-2));}void adjust(){ int i,j; for(j=0; j<15; j++) { int m=0; for(i=0; i<10; i++) { map[m][j]=map[i][j]; if(map[i][j]!=' ') { if(i>m) map[i][j]=' '; m++; } } } int k=0; for(j=0; j<15; j++) { for(i=0; i<10; i++) map[i][k]=map[i][j]; int flag=0; for(i=0; i<10; i++) { if(map[i][j]!=' ') { flag=1; break; } } if(flag) { if(j>k) { for(i=0; i<10; i++) map[i][j]=' '; } k++; } }}int main(){ int i,j,k,n; int time=0; scanf("%d",&n); while(n--) { for(i=9; i>=0; i--) { scanf("%s",map[i]); } score=0; printf("Game %d: \n\n",++time); ttt=0; int ti=0,last; while(1) { int t=0,block[200]; memset(vis,0,sizeof(vis)); for(j=0; j<15; j++) { for(i=0; i<10; i++) { if(vis[i][j]==0 && map[i][j]!=' ') { t=t+1; block[t]=bfs(i,j,t); } } } int ma=0,ar; last=0; for(i=1; i<=t; i++) { last+=block[i]; if(ma<block[i]) { ma=block[i]; ar=i; } } if(ma<=1) { if(ma==0) score+=1000; break; } else { remov(ar,ma); score+=(ma-2)*(ma-2); adjust(); } } printf("Final score: %d, with %d balls remaining. \n\n",score,last); } return 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 1027 The Same Game
- poj 1027 The Same Game
- POJ 1027--The Same Game
- POJ 1027The Same Game
- The Same Game POJ
- poj1027 The Same Game (简单模拟题)
- POJ 1027 The Same Game BFS
- POJ 1027 The Same Game 大暴消
- POJ 1027 The Same Game 笔记 未完成
- poj1027--The Same Game(模拟)
- The Same Game-POJ1027模拟
- C#控件缩写
- 用户抛弃你的网站的10条原因
- VB.net学习笔记(三)调试
- 保存学生信息到文件(数组内元素排序, io操作)
- C#多态实现之抽象类
- POJ 1027 The Same Game 模拟题
- 处理百万级以上的数据查询提高效率的办法
- 网络编程之recv send研究
- Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
- 对Git的一些理解
- 【图论】bfs树与dfs树的两个妙用
- Spring学习之——依赖关系和配置细节(一)
- cell组件注册码
- 分治算法--1. 二分查找