zoukankan      html  css  js  c++  java
  • [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;
    }
    
  • 相关阅读:
    吴裕雄--天生自然ANDROID开发学习:3.3 Handler消息传递机制浅析
    吴裕雄--天生自然ANDROID开发学习:3.2 基于回调的事件处理机制
    吴裕雄--天生自然ANDROID开发学习:3.1.1 基于监听的事件处理机制
    吴裕雄--天生自然ANDROID开发学习:2.6.4 DrawerLayout(官方侧滑菜单)的简单使用
    吴裕雄--天生自然ANDROID开发学习:2.6.3 ViewPager的简单使用
    吴裕雄--天生自然ANDROID开发学习:2.6.2 菜单(Menu)
    吴裕雄--天生自然ANDROID开发学习:2.6.1 PopupWindow(悬浮框)的基本使用
    吴裕雄--天生自然ANDROID开发学习:2.6.0 其他几种常用对话框基本使用
    吴裕雄--天生自然ANDROID开发学习:2.5.9 AlertDialog(对话框)详解
    bzoj 3874: [Ahoi2014&Jsoi2014]宅男计划
  • 原文地址:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/5813212.html
Copyright © 2011-2022 走看看