codeforces 1004 B. Sonya and Exhibition

题意:

给出两个数 n,m; 要求输出一个长度为n 的01字符串使得给出的m个区间价值之和最大,每个的区间价值等于区间里0的个数和一的个数的乘积。 

思路: 

仔细想想其实和区间没啥关系,因为我们保证每个区间的价值最大就可以了,区间的长度是一定的,就是0和1的个数是一定的。热然后要求乘积最大,其实就是个初中的不等式。。。

当且仅当

  时取等号  =成立


#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int  n,m;
    scanf("%d%d",&n,&m);
    int x;
    for(int i = 1;i<=m*2;i++)
    {
        scanf("%d",&x);
    }
    for(int i = 1;i<=n;i++)
    {
        if(i%2)
            putchar('0');
        else
            putchar('1');
    }
    putchar('\n');
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Theflowerofac/article/details/81749180