Codeforces Round #429 (Div. 2) B C

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

Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?

Input

First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.

Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output

Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).

Examples
Input
4
1 3 2 3
Output
First
Input
2
2 2
Output
Second
Note

In first sample first player remove whole array in one move and win.

In second sample first player can't make a move and lose.

 题意是:First可以取一段区间之和是奇数的,Second可以取一段区间是偶数的。

由于是奇偶关系,可以把所以的数都变成1和0。然后求前缀和,是奇数的话一定是First赢,是偶数的话只要sum为0才是Second赢。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int N = 1e6+10;
 5 int sum;
 6 int main() {
 7     int n, x;
 8     scanf("%d", &n);
 9     for(int i = 0; i < n; i ++) {
10         scanf("%d", &x);
11         x %= 2;
12         sum += x;
13     }
14     if(sum&1 || (sum%2==0 && sum > 0))printf("First\n");
15     else printf("Second\n");
16 }
C. Leha and Function
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets.

But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays A and B, each consists of m integers. For all i, j such that 1 ≤ i, j ≤ m the condition Ai ≥ Bj holds. Help Leha rearrange the numbers in the array A so that the sum is maximally possible, where A' is already rearranged array.

Input

First line of input data contains single integer m (1 ≤ m ≤ 2·105) — length of arrays A and B.

Next line contains m integers a1, a2, ..., am (1 ≤ ai ≤ 109) — array A.

Next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109) — array B.

Output

Output m integers a'1, a'2, ..., a'm — array A' which is permutation of the array A.

Examples
Input
5
7 3 5 3 4
2 1 3 2 3
Output
4 7 3 5 3
Input
7
4 6 5 8 8 2 6
2 1 2 2 1 1 2
Output
2 6 4 5 8 8 6

 求使的这个最大的序列A'  ,f(n,k)的意思不好说,就按说明里的例子说,{1,2,3,4}那个f(4,2) 就是从前4个中取两个元素,取两个元素中小的那个

这个例子有6个两个元素的{1,2}、{1,3}、{1,4}、{2,3}、{2,4}、{3,4} 最小的分别是 1,1,1,2,2,3 所以期望是(1+1+1+2+2+3)/6.

看第一、二的样例,大胆的猜了一个规律,还真1A了,就是A数组和B数组是最大的数子与最小的数子对应。希望今天起来能真正的AC

-------------------------8-19 9:22--更新线----------------------------------------------

事实证明这猜想是对的,已经AC了。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int N = 2e5+10;
 5 int a[N], aa[N];
 6 struct Nod{
 7     int x, index;
 8 }nod[N];
 9 bool cmp(Nod a, Nod b) {
10     return a.x > b.x;
11 }
12 int main() {
13     int m;
14     scanf("%d", &m);
15     for(int i = 0; i < m; i ++) scanf("%d", &a[i]);
16     for(int i = 0; i < m; i ++) scanf("%d", &nod[i].x),nod[i].index = i;
17     sort(nod,nod+m,cmp);
18     sort(a,a+m);
19     for(int i = 0; i < m; i ++) {
20         aa[nod[i].index] = a[i];
21     }
22     for(int i = 0; i < m; i ++) {
23         printf("%d%c",aa[i],(i==m-1 ?'\n':' '));
24     }
25     return 0;
26 }

 

posted @ 2017-08-19 01:12  starry_sky  阅读(620)  评论(0编辑  收藏  举报