zoukankan      html  css  js  c++  java
  • cf299C Weird Game

    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.

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

    Example

    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,别人能取1),优先取(1,1),然后有(1,0)优先取,再然后有(0,1)优先取,然后没有然后了
     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<queue>
     8 #include<deque>
     9 #include<set>
    10 #include<map>
    11 #include<ctime>
    12 #define LL long long
    13 #define inf 0x7ffffff
    14 #define pa pair<int,int>
    15 #define mkp(a,b) make_pair(a,b)
    16 #define pi 3.1415926535897932384626433832795028841971
    17 #define mod 100007
    18 using namespace std;
    19 inline LL read()
    20 {
    21     LL x=0,f=1;char ch=getchar();
    22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    23     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    24     return x*f;
    25 }
    26 char s[2000010],t[2000010];
    27 int a,b1,b2,c;
    28 int n,s1,s2;
    29 inline void choose(int &b1,int &b2,int &s1)
    30 {
    31     if (a){a--;s1++;return;}
    32     if (b1){b1--;s1++;return;}
    33     if (b2){b2--;return;}
    34     c--;
    35 }
    36 int main()
    37 {
    38     n=read()*2;
    39     scanf("%s",s+1);
    40     scanf("%s",t+1);
    41     for(int i=1;i<=n;i++)
    42         if (s[i]=='1'&&t[i]=='1')a++;
    43         else if (s[i]=='1'&&t[i]=='0')b1++;
    44         else if (s[i]=='0'&&t[i]=='1')b2++;
    45         else c++;
    46     n/=2;
    47     for (int i=1;i<=n;i++)
    48     {
    49         choose(b1,b2,s1);
    50         choose(b2,b1,s2);
    51     }
    52     if (s1>s2)puts("First");
    53     else if (s1==s2)puts("Draw");
    54     else puts("Second");
    55 }
    cf 299C


    ——by zhber,转载请注明来源
  • 相关阅读:
    Django学习之八:forms组件【对form舒心了】
    Django学习之七:Django 中间件
    Django学习之六:Django 常用模块导入记忆
    Django学习之五:Django 之 注意事项及汇总
    Django学习之四:Django Model模块
    工程师基本常识
    Redis详解
    Nginx浅析
    MySQL数据库引擎、事务隔离级别、锁
    浅谈HTTP中GET和POST请求方式的区别
  • 原文地址:https://www.cnblogs.com/zhber/p/7152993.html
Copyright © 2011-2022 走看看