Croc Champ 2013 - Round 2 (Div. 2 Edition) C

 C. Weird Game

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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
 
 
貪心,儘量拿分
不知道怎麼證明
一開始肯定是搶11的,自己拿分的同時減別人的分數
然後無論11的個數是奇數還是偶數
都可以轉化成 first的領先一分(偶數情況是拿完11之後first拿一分)
這時候變成second先手
然後,不知道怎麼解釋了
貪心過
  1. #include<cstdio> 
  2. using namespace std; 
  3. char a[2000010],b[2000010]; 
  4.  
  5. int main() 
  6.     int n; 
  7.     scanf("%d",&n); 
  8.     getchar(); 
  9.     for (int i = 0 ; i < 2*n ; i++) scanf("%c",&a[i]); 
  10.     getchar(); 
  11.     for (int i = 0 ; i < 2*n ; i++) scanf("%c",&b[i]); 
  12.     int num[4] = {0,0,0,0}; 
  13.     for (int i = 0 ; i < 2*n ; i++) 
  14.     { 
  15.         if (a[i] == '1' && b[i] == '1') num[3]++; 
  16.         if (a[i] == '1' && b[i] == '0') num[2]++; 
  17.         if (a[i] == '0' && b[i] == '1') num[1]++; 
  18.         if (a[i] == '0' && b[i] == '0') num[0]++; 
  19.     } 
  20.     int ans1 = 0 ,ans2 = 0; 
  21.     if (num[3] % 2 == 0) 
  22.     { 
  23.         ans1++; 
  24.         num[2]--; 
  25.         if (num[1] > num[2]) 
  26.             { 
  27.                 ans2++; 
  28.                 ans2 += (num[1]-num[2]-1) / 2; 
  29.             } 
  30.             if (num[2] > num[1]) ans1 += (num[2]-num[1]+1) / 2; 
  31.     } 
  32.     else 
  33.     { 
  34.         ans1 = 1; 
  35.         if (num[2] != num[1]) 
  36.         { 
  37.             if (num[1] > num[2]) 
  38.             { 
  39.                 ans2++; 
  40.                 ans2 += (num[1]-num[2]-1) / 2; 
  41.             } 
  42.             if (num[2] > num[1]) ans1 += (num[2]-num[1]+1) / 2; 
  43.         } 
  44.     } 
  45.     if (ans1 > ans2) printf("First\n"); 
  46.     if (ans1 == ans2) printf("Draw\n"); 
  47.     if (ans1 < ans2) printf("Second\n"); 
  48.     return 0; 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章