UVA141- The Spot Game【运行时间:25ms】
来源:互联网 发布:农村淘宝是什么意思 编辑:程序博客网 时间:2024/05/22 01:47
题目大意:两个玩家依次在棋盘上下棋,每次可以选择放下一枚黑子‘+’或者取走一枚黑子‘-’,当一个玩家操作完成后,如果棋盘布局出现此前出现过的情况,则该玩家输掉了比赛。(相同的棋盘布局考虑棋盘转动90度、180度、270度的等价棋盘)
解法:使用字符串来表示棋盘。使用map来记录每种棋盘布局出现的状态,并且同时对等价的棋局+1.那么出现次数>1时该玩家输掉比赛。
map<string,int>
#include <iostream>#include <map>#include <string>#include <cstdio>using namespace std;map<string,int> mymap;string str,str1,str2,str3;int n;void tra1(){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ str1[n*j+n-i-1]=str[n*i+j]; } }}void tra2(){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ str2[n*(n-i-1)+n-j-1]=str[n*i+j]; } }}void tra3(){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ str3[n*(n-j-1)+i]=str[n*i+j]; } }}int main(){ int a,b,sign,temp; char c; while(scanf("%d",&n)!=EOF){ mymap.clear(); temp=0; sign=0; if(n==0) return 0; str="0"; for(int i=0;i<=n*n;i++){ str.push_back('0'); } str1=str; str3=str; str2=str; for(int i=0;i<2*n;i++){ scanf("%d%d %c",&a,&b,&c); if(c=='+'){str[(a-1)*n+b-1]='1';} else if(c=='-'){str[(a-1)*n+b-1]='0';} tra1(); tra2(); tra3(); mymap[str]++; if(str1!=str) mymap[str1]++; if(str2!=str1&&str2!=str) mymap[str2]++; if(str3!=str2&&str3!=str1&&str3!=str) mymap[str3]++; if(mymap[str]>1&&sign==0) { temp=i; sign=1; } } if(sign==0) printf("Draw\n"); else printf("Player %d wins on move %d\n",(temp+1)%2+1,temp+1); }}
0 0
- UVA141- The Spot Game【运行时间:25ms】
- uva141 - The Spot Game
- [哈希]The Spot Game uva141
- uva141 - The Spot Game(斑点游戏)
- 141 - The Spot Game
- 141The Spot Game
- Uva 141 The spot game
- UVa 141 The Spot Game
- uva 141 - The Spot Game
- uva 141 The Spot Game
- UVa 141 - The Spot Game
- UVA 141 - The Spot Game
- UVA 141 - The Spot Game
- UVa:141 The Spot Game
- The Spot Game +hash表
- UVA 141 - The Spot Game
- UVA - 141 The Spot Game
- UVa 141 - The Spot Game
- hdu2048 神、上帝以及老天爷
- 那总是在时尚经典的服装风格
- Linux Makefile
- CentOS安装rpm包时遇到Header V3 DSA signature: NOKEY时解决办法
- hdu 1823 Luck and Love 二维线段树
- UVA141- The Spot Game【运行时间:25ms】
- SQL中DML(数据库操作语言)的使用
- Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE 安卓程序启动报错,
- google-sdk-动态更新手机主题(简单版)
- android 技巧
- SSL通关之keytool 命令(二)
- 迷人的巴宝莉时装附件配置
- 迷人和漂亮的十几岁的明星
- java二十三种设计模式----(二)单例设计模式 :“懒汉式”与“饿汉式”的区别 为什么通常使用饿汉式