codeforces Team Tic Tac Toe

题面

Farmer John owns 26 cows, which by happenstance all have names starting with different letters of the alphabet, so Farmer John typically refers to each cow using her first initial – a character in the range A…Z.

The cows have recently become fascinated by the game of tic-tac-toe, but since they don’t like the fact that only two cows can play at a time, they have invented a variant where multiple cows can play at once! Just like with regular tic-tac-toe, the game is played on a 3×3 board, only instead of just Xs and Os, each square is marked with a single character in the range A…Z to indicate the initial of the cow who claims that square.

An example of a gameboard might be:

COW
XXO
ABC
The cows fill in each of the nine squares before they become confused about how to figure out who has won the game. Clearly, just like with regular tic-tac-toe, if any single cow has claimed an entire row, column, or diagonal, that cow could claim victory by herself. However, since the cows think this might not be likely given the larger number of players, they decide to allow cows to form teams of two, where a team of two cows can claim victory if any row, column, or diagonal consists only of characters belonging to the two cows on the team, and moreover if characters from both cows (not just one) are used in this row, column, or diagonal.

Please help the cows figure out how many individuals or two-cow teams can claim victory. Note that the same square on the game board might possibly be usable in several different claims to victory.

Input
The input consists of three lines, each of which is three characters in the range A…Z.

Output
Output should consist of two lines. On the first line, output the number of individual cows who can claim victory. On the second line, output the number of two-cow teams that could claim victory.

题意

3×3井字棋,不同的是每个空可以是26个大写字母中的一个,而且可以两个字母组队,给你一副局面,问你个人的有多少赢了,组队的有多少赢了

分析

3×3,26个字母,8说了,开冲(模拟)。

代码

#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long ll;
int main(){
	char s[5][5];
	int person[30]={0},team[30][30]={0},i,j;
	for(i=0;i<3;i++) scanf("%s",s[i]);
	for(i=0;i<3;i++){//行 
		int cnt=1,flag=0;
		if(s[i][1]!=s[i][0]) cnt++,flag=1;
		if(s[i][2]!=s[i][1] && s[i][2]!=s[i][0]) cnt++;
		if(cnt==2){
			if(flag){
				if(s[i][1]<s[i][0]) team[s[i][1]-'A'][s[i][0]-'A']++;
				else team[s[i][0]-'A'][s[i][1]-'A']++;
			}else{
				if(s[i][2]<s[i][0]) team[s[i][2]-'A'][s[i][0]-'A']++;
				else team[s[i][0]-'A'][s[i][2]-'A']++;
			}
		}
		if(cnt==1) person[s[i][0]-'A']++; 
	}
	for(j=0;j<3;j++){//列 
		int cnt=1,flag=0;
		if(s[1][j]!=s[0][j]) cnt++,flag=1;
		if(s[2][j]!=s[1][j] && s[2][j]!=s[0][j]) cnt++;
		if(cnt==2){
			if(flag){
				if(s[1][j]<s[0][j]) team[s[1][j]-'A'][s[0][j]-'A']++;
				else team[s[0][j]-'A'][s[1][j]-'A']++;
			}else{
				if(s[2][j]<s[0][j]) team[s[2][j]-'A'][s[0][j]-'A']++;
				else team[s[0][j]-'A'][s[2][j]-'A']++;
			}
		}
		if(cnt==1) person[s[0][j]-'A']++; 
	}
	int cnt=1,flag=0;
	if(s[1][1]!=s[0][0]) cnt++,flag=1;
	if(s[2][2]!=s[1][1] && s[2][2]!=s[0][0]) cnt++;
	if(cnt==2){
		if(flag){
			if(s[1][1]<s[0][0]) team[s[1][1]-'A'][s[0][0]-'A']++;
			else team[s[0][0]-'A'][s[1][1]-'A']++;
		}else{
			if(s[2][2]<s[0][0]) team[s[2][2]-'A'][s[0][0]-'A']++;
			else team[s[0][0]-'A'][s[2][2]-'A']++;
		}
	}
	if(cnt==1) person[s[0][0]-'A']++;
	
	cnt=1,flag=0;
	if(s[1][1]!=s[0][2]) cnt++,flag=1;
	if(s[2][0]!=s[1][1] && s[2][0]!=s[0][2]) cnt++;
	if(cnt==2){
		if(flag){
			if(s[1][1]<s[0][2]) team[s[1][1]-'A'][s[0][2]-'A']++;
			else team[s[0][2]-'A'][s[1][1]-'A']++;
		}else{
			if(s[2][0]<s[0][2]) team[s[2][0]-'A'][s[0][2]-'A']++;
			else team[s[0][2]-'A'][s[2][0]-'A']++;
		}
	}
	if(cnt==1) person[s[0][2]-'A']++;
	int ans;
	for(ans=0,i=0;i<30;i++) if(person[i]) ans++;
	printf("%d\n",ans); 
	for(ans=0,i=0;i<30;i++){
		for(j=0;j<30;j++){
			if(team[i][j]) ans++;
		}
	}
	printf("%d\n",ans); 
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值