C - Semifinals

来源:互联网 发布:京东微信端口什么意思 编辑:程序博客网 时间:2024/05/29 03:49

Description

Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the n - 2k of the best among the others.

The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of participants in each semifinal.

Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109) — the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1a2, ..., an and b1b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.

Output

Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".

Sample Input

Input
49840 99209860 99809930 1002010040 10090
Output
11101100
Input
49900 98509940 993010000 1002010060 10110
Output
11001100
分析:这道题还是主要地读题,学好英语还是很重要的。大意:两个半决赛刚刚跑步比赛。每个半决赛都有n个参与者。有n个参与者进军总决赛,他们选择如下:从每个半决赛,我们选择k(0≤2 k≤n)人显示最好的结果在半决赛和决赛中所有其他地方去的人还没有排名在前k的半决赛,但得n - 2 k中最好的。    比赛组织者尚未确定k值,所以参与者想知道还有谁有机会进入决赛,谁能回家。
参考代码如下:
#include<stdio.h>#include<string.h>int a[1000010],b[1000010];void ans(int k,int n){    for(int i=0;i<=k;i++)    printf("1");    for(int i=k+1;i<n;i++)    printf("0");}int max(int a,int b){    return (a>b)?a:b;}int main(){    int n;    scanf("%d",&n);    for(int i=0;i<n;i++)    scanf("%d%d",&a[i],&b[i]);    int i=0,j=0,num=0;    while(num<n)    {        if(a[i]<b[j])        i++;        else j++;        num++;    }    int k=max(i-1,n/2-1);    ans(k,n);    printf("\n");    k=max(j-1,n/2-1);    ans(k,n);    return 0;}
0 0
原创粉丝点击