Croc Champ 2013 - Round 2 (Div. 2 Edition)——A,B,C

来源:互联网 发布:软件专业等级证书 编辑:程序博客网 时间:2024/05/19 11:39
A. Ksusha and Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.

Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!

Input

The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers the array has. The next line contains integers a1, a2, ..., an(1 ≤ ai ≤ 109) — the array elements.

Output

Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.

If there are multiple answers, you are allowed to print any of them.

因为要能被所有数整除而且这个数要出现,找最小的(排序)验证即可。

B. Ksusha the Squirrel
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1.

Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.

Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k.

Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?

Input

The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#".

It is guaranteed that the first and the last characters equal ".".

Output

Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).

统计串中有没有超过k的连续#即可。

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.

判断两人可以拿的1是否一样多。

比赛时只把特判加在  11 出现奇数次的情况下过了,忘了偶数情况下同样存在这样的特判。

分析:

1.当11数量为偶数时,不会对先后手情况造成影响,而且对输赢也不会产生影响。A总可以和Y拿同样的11.因为Y存在先手优势,所以当后手的01比先手的10多一次时,Y总可以再取01消除A的一个1.

所以当11数量为偶数时,不论是Y的01和A的10一样多还是Y的01比A的10多一个,总可以达到相等的局面。

2.当11数量为奇数时,会对先后手情况造成影响,即Y变为后手,但由于Y多拿了一个1,可以将Y的总数量加1.

若此时Y的10比A的01出现次数少1个时,总可以达到相等的局面。

当Y的10比A的01次数少2个时,作为后手的Y同样可以最后取一个01来消除A的一个1.再加上Y先多取的一个1,两者也是相等的局面。

详见这样一组例子:

3

010100

011011

Draw

#include <cstring>#include <algorithm>#include <cstdio>#include <string>#include <vector>#include <iostream>using namespace std;const int maxn=2000000+5;char s[maxn],t[maxn];int main(){    int n;    cin>>n;    cin>>s>>t;    int num=0,num1=0,num2=0;    for(int i=0;i<2*n;i++)    {        if(s[i]=='1'&&t[i]=='1') num++;        if(s[i]=='1'&&t[i]=='0') num1++;        if(s[i]=='0'&&t[i]=='1') num2++;    }    if(num%2==0){        if(num1==num2||num2==num1+1) cout<<"Draw";        else if(num1<num2) cout<<"Second";        else cout<<"Draw";        return 0;    }    num1++;    if(num1==num2||num2==num1+1) cout<<"Draw";    else if(num1>num2) cout<<"First";    else cout<<"Second";    return 0;}