Sonya and Exhibition 1004B
1 second
256 megabytes
standard input
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.
The first line contains two integers nn and mm (1≤n,m≤1031≤n,m≤103) — the number of flowers and visitors respectively.
Each of the next mm lines contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n), meaning that ii-th visitor will visit all flowers from lili to ririinclusive.
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.
5 3
1 3
2 4
2 5
01100
6 3
5 6
1 4
4 6
110010
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][1…3], there are one rose and two lilies, so the beauty is equal to 1⋅2=21⋅2=2;
- in the segment [2…4][2…4], there are one rose and two lilies, so the beauty is equal to 1⋅2=21⋅2=2;
- in the segment [2…5][2…5], there are two roses and two lilies, so the beauty is equal to 2⋅2=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 [5…6][5…6], there are one rose and one lily, so the beauty is equal to 1⋅1=11⋅1=1;
- in the segment [1…4][1…4], there are two roses and two lilies, so the beauty is equal to 2⋅2=42⋅2=4;
- in the segment [4…6][4…6], there are two roses and one lily, so the beauty is equal to 2⋅1=22⋅1=2.
The total beauty is equal to 1+4+2=71+4+2=7.
题意:在一个展览中,有n朵花,可以是玫瑰花,可以是百合花,有m个人,给出他们的观察区间,求出他们观察区间的最大美丽值,美丽值等于观察区间里玫瑰的数量乘以百合的数量。
分析:如果要两个数的乘积最大,那么这两个数要么相等,要么只差1。比如观察区间为(1,4),一共有4朵花,如果玫瑰2朵,百合2朵,乘积为4;如果玫瑰3朵,百合1朵,乘积为3。所以只要让玫瑰和百合的分配变成一朵玫瑰,一朵百合就行。
#include<cstdio>
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
int a,b;
for(int i=;i<=m;i++)
scanf("%d %d",&a,&b);
for(int i=;i<=n;i++)
{
if(i%==)
printf("");
else
printf("");
}
printf("\n");
}
return ;
}
Sonya and Exhibition 1004B的更多相关文章
- B - Sonya and Exhibition CodeForces - 1004B (思维题)
B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input stand ...
- [Codeforces Round495B] Sonya and Exhibition
[题目链接] https://codeforces.com/contest/1004/problem/B [算法] 不难发现 , 最优解一定是01010101.... 时间复杂度 : O(N) [代码 ...
- Sonya and Exhibition
http://codeforces.com/group/1EzrFFyOc0/contest/1004/problem/B #include<iostream> #include<c ...
- Codeforces Round #495 (Div. 2) B
题目链接:http://codeforces.com/contest/1004/problem/B B. Sonya and Exhibition time limit per test 1 seco ...
- cordforce 495 补题 <未完>
题目链接: http://codeforces.com/contest/1004/my A. Sonya and Hotels 分类讨论 看第一个样例解释的时候没看到后面第二行还有一个19,想了半天为 ...
- CodeForces - 1004B
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she ...
- Codeforces713C Sonya and Problem Wihtout a Legend(DP)
题目 Source http://codeforces.com/problemset/problem/713/C Description Sonya was unable to think of a ...
- (01背包变形) Cow Exhibition (poj 2184)
http://poj.org/problem?id=2184 Description "Fat and docile, big and dumb, they look so stupid ...
- Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
随机推荐
- python的导包问题
有事会遇到在python代码中导入包错误问题,本文简单对python包的引入做简单介绍 简单说,我认为python导包一共有3种情况,分别是: 要导的包与当前文件在同一层要导的包在当前文件的底层(就是 ...
- Elasticsearch的JavaAPI
获取客户端对象 public class App { private TransportClient client; //获取客户端对象 @Before public void getClinet() ...
- Json1:使用gson解析、生成json
Json解析: 1.json第三方解析包:json-lib.gson.jackson.fastjson等2.Google-gson只兼容jdk1.5版本以上:JSON-lib分别支持1.4和1.53. ...
- 小众Python库介绍
Python 是世界上发展最快的编程语言之一.它一次又一次地证明了自己在开发人员和跨行业的数据科学中的实用性.Python 及其机器学习库的整个生态系统使全世界的用户(无论新手或老手)都愿意选择它.P ...
- Nginx 之防盗链配置
首先,我们需要知道通过什么来实现防盗的! http referer 是header的一部分,当浏览器向web服务器发送请求的时候,一般会带上referer,这是在告诉服务器是从哪个页面链接过来的,服务 ...
- JQ获取地址栏参数
//获取地址栏参数 function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + " ...
- mke2fs
mke2fs - create an ext2/ext3/ext4 filesystem # mke2fs -b -c -N -t ext4 /dev/sdb #(注意末尾是/dev/sdb....? ...
- 42.scrapy爬取数据入库mongodb
scrapy爬虫采集数据存入mongodb采集效果如图: 1.首先开启服务切换到mongodb的bin目录下 命令:mongod --dbpath e:\data\db 另开黑窗口 命令:mongo. ...
- 《算法》第六章部分程序 part 4
▶ 书中第六章部分程序,包括在加上自己补充的代码,利用后缀树查找最长重复子串.查找最大重复子串并输出其上下文(Key word in context,KWIC).求两字符串的最长公共子串 ● 利用后缀 ...
- <转载> maven 详解 http://www.cnblogs.com/binyue/p/4729134.html
--声明规范 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3 ...