Codeforces1004B——Sonya and Exhibition

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 n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should contain exactly one flower: a rose or a lily.
She knows that exactly m people will visit this exhibition. The i-th visitor will visit all flowers from li to ri 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 n and m (1≤n,m≤103) — the number of flowers and visitors respectively.
Each of the next m lines contains two integers li and ri (1≤li≤ri≤n), meaning that i-th visitor will visit all flowers from li to ri inclusive.
Output
Print the string of n characters. The i-th symbol should be «0» if you want to put a rose in the i-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any.
Examples
Input
5 3
1 3
2 4
2 5
Output
01100
Input
6 3
5 6
1 4
4 6
Output
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 [1…3], there are one rose and two lilies, so the beauty is equal to 1⋅2=2;
in the segment [2…4], there are one rose and two lilies, so the beauty is equal to 1⋅2=2;
in the segment [2…5], there are two roses and two lilies, so the beauty is equal to 2⋅2=4.
The total beauty is equal to 2+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 [5…6], there are one rose and one lily, so the beauty is equal to 1⋅1=1;
in the segment [1…4], there are two roses and two lilies, so the beauty is equal to 2⋅2=4;
in the segment [4…6], there are two roses and one lily, so the beauty is equal to 2⋅1=2.
The total beauty is equal to 1+4+2=7.

感觉cf很喜欢搞01串…
这题读懂题意就不难了,要构造一个01串,使得询问的q个区间中,1的个数和0的个数相乘的和最大,很明显,要乘积最大,那么01串中0和1的个数要尽量均分,那就是0101交替了,这样无论如何询问区间,0和1的个数最多差1

代码:

#include <cstdio>
#include <algorithm>
using namespace std;
int main(void){
    int n,m,a,b;
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&a,&b);
    }
    bool flag=true;
    for(int i=0;i<n;i++){
        if(flag){
            printf("0");
            flag=false;
        }
        else{
            printf("1");
            flag=true;
        }
    }
    printf("\n");
    return 0;
}
全部评论

相关推荐

刚刷到字节跳动官方发的消息,确实被这波阵仗吓了一跳。在大家还在纠结今年行情是不是又“寒冬”的时候,字节直接甩出了史上规模最大的转正实习计划——ByteIntern。咱们直接看几个最硬的数,别被花里胡哨的宣传词绕晕了。首先是“量大”。全球招7000多人是什么概念?这几乎是把很多中型互联网公司的总人数都给招进来了。最关键的是,这次的资源分配非常精准:研发岗给了4800多个Offer,占比直接超过六成。说白了,字节今年还是要死磕技术,尤其是产品和AI领域,这对于咱们写代码的同学来说,绝对是今年最厚的一块肥肉。其次是大家最关心的“转正率”。官方直接白纸黑字写了:整体转正率超过50%。这意味着只要你进去了,不划水、正常干,每两个人里就有一个能直接拿校招Offer。对于2027届(2026年9月到2027年8月毕业)的同学来说,这不仅是实习,这简直就是通往大厂的快捷通道。不过,我也得泼盆冷水。坑位多,不代表门槛低。字节的实习面试出了名的爱考算法和工程实操,尤其是今年重点倾斜AI方向,如果你简历里有和AI相关的项目,优势还是有的。而且,转正率50%也意味着剩下那50%的人是陪跑的,进去之后的考核压力肯定不小。一句话总结:&nbsp;27届的兄弟们,别犹豫了。今年字节这是铁了心要抢提前批的人才,现在投递就是占坑。与其等到明年秋招去千军万马挤独木桥,不如现在进去先占个工位,把转正名额攥在手里。
喵_coding:别逗了 50%转正率 仔细想想 就是转正与不转正
字节7000实习来了,你...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务