zoukankan      html  css  js  c++  java
  • Codeforces Round #495 (Div. 2) B

    题目链接:http://codeforces.com/contest/1004/problem/B

    B. Sonya and Exhibition
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.

    There are nn flowers in a row in the exhibition. Sonya can put either a rose or a lily in the ii-th position. Thus each of nn positions should contain exactly one flower: a rose or a lily.

    She knows that exactly mm people will visit this exhibition. The ii-th visitor will visit all flowers from lili to riri inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.

    Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

    Input

    The first line contains two integers nn and mm (1n,m1031≤n,m≤103) — the number of flowers and visitors respectively.

    Each of the next mm lines contains two integers lili and riri (1lirin1≤li≤ri≤n), meaning that ii-th visitor will visit all flowers from lili to ririinclusive.

    Output

    Print the string of nn characters. The ii-th symbol should be «0» if you want to put a rose in the ii-th position, otherwise «1» if you want to put a lily.

    If there are multiple answers, print any.

    Examples
    input
    Copy
    5 3
    1 3
    2 4
    2 5
    output
    Copy
    01100
    input
    Copy
    6 3
    5 6
    1 4
    4 6
    output
    Copy
    110010
    Note

    In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;

    • in the segment [13][1…3], there are one rose and two lilies, so the beauty is equal to 12=21⋅2=2;
    • in the segment [24][2…4], there are one rose and two lilies, so the beauty is equal to 12=21⋅2=2;
    • in the segment [25][2…5], there are two roses and two lilies, so the beauty is equal to 22=42⋅2=4.

    The total beauty is equal to 2+2+4=82+2+4=8.

    In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;

    • in the segment [56][5…6], there are one rose and one lily, so the beauty is equal to 11=11⋅1=1;
    • in the segment [14][1…4], there are two roses and two lilies, so the beauty is equal to 22=42⋅2=4;
    • in the segment [46][4…6], there are two roses and one lily, so the beauty is equal to 21=22⋅1=2.

    The total beauty is equal to 1+4+2=71+4+2=7.

    题意: 给出一个n朵花,m个游客的访问区间,它可以在每个位置放0或1 ,然后它有一个漂亮程度的方法,在给定的区间里面,0的个数乘以1的个数就是他的漂亮程度,求怎么摆放0 1才能使漂亮程度最高

    思路:她给了m个区间,想想一个区间内怎么才能使值是最大的,无非就是0取一半1取一半,这个是肯定得,自己推一个例子就想得到,然后我们就可以进行下一步,要使每个区间得0 1数量各取一半

    首先这是一个构造题,答案不唯一,所以一般这种题都是一些考思维性的,一种固定的构造方法,我开始也是去想怎么合并区间,然后发现还是会有影响其他区间的01数,最后仔细的想了下,我无非就是

    要每个区间的01数各一半,而且又不影响其他其他区间,我们就可以>V< 010101,这种岔开的排列无论哪个区间肯定会各取一半,这个算是一个思维好题

    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    struct sss
    {
        int left,right;
    }a[1001];
    int main()
    {
        int n,m;
        char str[1001];
        scanf("%d%d",&n,&m);
        int l,r;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&a[i].left,&a[i].right);
        }
        for(int i=0;i<n;i++)
        {
            if(i%2) str[i]='1';
            else str[i]='0';
        }
        str[n]='';
        printf("%s",str);
    }
  • 相关阅读:
    如何用css画一个文件上传图案?
    Vue.js命名风格指南
    JS的静态类型检测,有内味儿了
    每天认识几个HTTP 响应码
    剑指offer二叉树算法题JavaScript整理
    javascript
    JS数据结构与算法
    (转自MDN)CSS基础一定要看的包含块(containing block)
    简单记记display中inline、block、inline-block以及常见行内/块内元素
    从计算机操作系统中了解并发与并行、进程与线程
  • 原文地址:https://www.cnblogs.com/Lis-/p/9328176.html
Copyright © 2011-2022 走看看