Weird Game CodeForces - 299C

游戏策略分析:二进制字符对决
本文探讨了一个基于二进制字符“0”和“1”的游戏策略,两名玩家轮流选择字符以形成最大的数字,目标是通过最优策略确定最终胜利者。文章提供了详细的分析过程及代码实现。

Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn’t show up, Yaroslav and Andrey play another game.

Roman leaves a word for each of them. Each word consists of 2·n binary characters “0” or “1”. After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn’t been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string.

Let’s represent Yaroslav’s word as s = s1s2… s2n. Similarly, let’s represent Andrey’s word as t = t1t2… t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper.

The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw.

You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well.

Input
The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav’s word. The third line contains string t — Andrey’s word.

It is guaranteed that both words consist of 2·n characters “0” and “1”.

Output
Print “First”, if both players play optimally well and Yaroslav wins. If Andrey wins, print “Second” and if the game ends with a draw, print “Draw”. Print the words without the quotes.

Examples
Input
2
0111
0001
Output
First
Input
3
110110
001001
Output
First
Input
3
111000
000111
Output
Draw
Input
4
01010110
00101101
Output
First
Input
4
01100000
10010011
Output
Second

两个人玩游戏,第一个人选过的地方,第二个人就不能选了。看看最后是谁选的一多。
分析一下:如果两个字符串相同的地方都是1,那么就看奇偶性就好了。

代码如下:

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
long n,i,f,g,h;
string s,t;
int main() {
	cin >> n >> s >> t;
	for (i=0;i<2*n;i++) {
		if (s[i]=='1') f++;
		if (t[i]=='1') g++;
		if (s[i]+t[i]==98) h++;
	}
	if (h%2==1) g--;
	if (f>g) cout << "First" << endl;
	else if (g-f>1) cout << "Second" << endl;
	else cout << "Draw" << endl;
	return 0;
}

努力加油a啊,(o)/~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值