Semifinals(技巧模拟)

B. Semifinals
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 a1, a2, ..., an and b1, b2, ..., 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 test(s)
input
4
9840 9920
9860 9980
9930 10020
10040 10090
output
1110
1100
input
4
9900 9850
9940 9930
10000 10020
10060 10110
output
1100
1100
Note

Consider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090.

  • If k = 0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals.
  • If k = 1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds).
  • If k = 2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.

 

      题意:

      给出 n (1 <= n <= 10^5),表示每列有 n 个数,一共有两列。随后给出这两列共 2n 个数,给出两列的数字按升序排序(升序对于某列单独来说)。按要求选择数字,给出 k (0 <= 2*k <= n),表示每次选两列各前 k 个数后,在剩下没有选的数中选全部数字最小的前 (n - 2k)个。最后输出两列各选择的情况,1代表被选上,0代表未被选上。

 

      思路:

      1.按 2 * k <= n 算出最大 k ,保证每列的前 k 个是一定会被选上的;

      2.按要求第一步选完后,每次不同的 k 都要选剩下的 (n - 2k) 个,故考虑选择剩下最大数量的情况,即 k == 0 的时候,要求选全部数字升序的前 n 个,故需要统计两列占前 n 个中各有几个用 num 表示;

      3.每列输出 1 和 0 情况比较 max(n / 2,num)即可。

 

      疑惑点:

      k 是在变化的,能否保证每次每列排除完 k 个后,选剩下的(n - 2k)个数一定包含在预处理的总序列的前 n 个之内?

      答:每次选择都是先选每个序列的前 k 个,那么总共所选的数量就是 2k 个,那么每次所选总共的数量就是 2k + (n - 2k) = n 个,说明剩下的个数一定包含在前 n 个之内。

 

      AC:

#include<cstdio>
#include<algorithm>
using namespace std;
int num1[100005],num2[100005];
int main()
{
    int n,num = 1;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
        scanf("%d%d",&num1[i],&num2[i]);
    int n1 = 0,n2 = 0;
    while(num <= n)
    {
        if(num1[n1] < num2[n2]) n1++;
        else                    n2++;
        num++;
    }
    n1 = max(n1,n / 2);
    n2 = max(n2,n / 2);
    for(int i = 1;i <= n;i++)
    {
        if(i <= n1) printf("1");
        else        printf("0");
    }
    printf("\n");
    for(int i = 1;i <= n;i++)
    {
        if(i <= n2) printf("1");
        else        printf("0");
    }
    printf("\n");
    return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值