• [codeforces 293]A. Weird Game


    [codeforces 293]A. Weird Game

    试题描述

    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 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 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.

    输入

    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 n characters "0" and "1".

    输出

    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.

    输入示例

    4
    01010110
    00101101

    输出示例

    First

    数据规模及约定

    见“输入

    题解

    每个人都可以贪心地取上下都是 1 的位置,取完了再取自己位置是 1 的位置,再完了就取对方是 1 的位置,最后取都是 0 的位置,最后谁 1 多谁赢。(就是遵循“利己损人”的贪心策略)

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <stack>
    #include <vector>
    #include <queue>
    #include <cstring>
    #include <string>
    #include <map>
    #include <set>
    using namespace std;
    
    const int BufferSize = 1 << 16;
    char buffer[BufferSize], *Head, *Tail;
    inline char Getchar() {
        if(Head == Tail) {
            int l = fread(buffer, 1, BufferSize, stdin);
            Tail = (Head = buffer) + l;
        }
        return *Head++;
    }
    int read() {
        int x = 0, f = 1; char c = getchar();
        while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
        while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
        return x * f;
    }
    
    #define maxn 2000010
    int n;
    char s1[maxn], s2[maxn];
    
    int main() {
    	n = (read() << 1);
    	scanf("%s%s", s1 + 1, s2 + 1);
    	
    	int cnt10 = 0, cnt01 = 0, cnt11 = 0, fir = 0, sec = 0;
    	for(int i = 1; i <= n; i++)
    		cnt10 += (s1[i] == '1' && s2[i] == '0'),
    		cnt01 += (s1[i] == '0' && s2[i] == '1'),
    		cnt11 += (s1[i] == '1' && s2[i] == '1');
    	sec = (cnt11 >> 1);
    	fir = cnt11 - sec;
    	if(cnt11 & 1) {
    		if(cnt01 < cnt10) {
    			fir += cnt01 + (cnt10 - cnt01 >> 1);
    			sec += cnt01;
    		}
    		if(cnt01 > cnt10) {
    			fir += cnt10;
    			sec += cnt10 + (cnt01 - cnt10 - (cnt01 - cnt10 >> 1));
    		}
    		if(cnt01 == cnt10) {
    			fir += cnt10;
    			sec += cnt01;
    		}
    	}
    	else {
    		if(cnt01 < cnt10) {
    			fir += cnt01 + (cnt10 - cnt01 - (cnt10 - cnt01 >> 1));
    			sec += cnt01;
    		}
    		if(cnt01 > cnt10) {
    			fir += cnt10;
    			sec += cnt10 + (cnt01 - cnt10 >> 1);
    		}
    		if(cnt01 == cnt10) {
    			fir += cnt10;
    			sec += cnt01;
    		}
    	}
    	
    	if(fir > sec) puts("First");
    	if(fir < sec) puts("Second");
    	if(fir == sec) puts("Draw");
    	
    	return 0;
    }
    
  • 相关阅读:
    计算机服务器分类
    二进制和十进制转换
    计算机发展历史
    Linux运维学习第二周记
    Linux运维学习第一周记
    使用正则表达式替换文件内容 分类: python 小练习 2013-08-13 15:07 332人阅读 评论(0) 收藏
    Python 中的 socket 编程 分类: socket 2013-08-10 17:17 377人阅读 评论(0) 收藏
    python简单的socket 服务器和客户端 分类: socket 2013-08-10 16:44 455人阅读 评论(0) 收藏
    Python Socket API 笔记 分类: socket 2013-08-10 15:06 2320人阅读 评论(0) 收藏
    vim 7的 无限回退功能 分类: ubuntu 2013-08-09 14:04 672人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/5813212.html
Copyright © 2020-2023  润新知