Codeforces Round #495 (Div. 2) B
题目链接:http://codeforces.com/contest/1004/problem/B
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个游客的访问区间,它可以在每个位置放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[];
int main()
{
int n,m;
char str[];
scanf("%d%d",&n,&m);
int l,r;
for(int i=;i<m;i++)
{
scanf("%d%d",&a[i].left,&a[i].right);
}
for(int i=;i<n;i++)
{
if(i%) str[i]='';
else str[i]='';
}
str[n]='\0';
printf("%s",str);
}
Codeforces Round #495 (Div. 2) B的更多相关文章
- Codeforces Round #495 (Div. 2) D. Sonya and Matrix
http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. ...
- Codeforces Round #495 (Div. 2) C. Sonya and Robots
http://codeforces.com/contest/1004/problem/C 题意: 在一行上有n个数字,现在在最左边和最右边各放置一个机器人,左右机器人各有一个数字p和q.现在这两个机器 ...
- Codeforces Round #495 (Div. 2) Sonya and Matrix
正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...
- Codeforces Round #495 (Div. 2) A,B,C
A题 1.新添加一间酒店,要求酒店离已有的最近的一间酒店的距离恰好等于d 2.最左和最右必定存在合适的两种情况 3.酒店之间的情况就要判断两间酒店间的距离: 小于2d,表示无法在这两间酒店中间找到合适 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- Practical Node.js摘录(2018版)第1,2章。
大神的node书,免费 视频:https://node.university/courses/short-lectures/lectures/3949510 另一本书:全栈JavaScript,学习b ...
- java中的Sort函数,你值得看
基于C语言中的sort如此这么方便,自然而然,java中也有类似C的sort函数. 1.普通数组:Arrays.sort(数组名,开始位置,结束位置). 2.类中属性排序: 模板: class A { ...
- 在word中粘贴的图片为什么显示不完整
一.背景 整理系统测试说明文档,截得图片粘贴到word中显示不完整. 二.错误问题 问题:在word中粘贴的图片为什么显示不完整,如图所示: 三.分析问题: 原因是原来设置的行间距是固定值,图片也作一 ...
- Oracle PL/SQL游标
游标的提出: SQL是面向集合的,其结果一般是集合量(多条记录),而PL/SQL的变量一本是标量,其一组变量异常一直只能存放一条记录.所以仅仅使用变量并不能完全满足SQL语句向应用程序输出数据的要求. ...
- python-flask-wtforms组件流程源码
在最开始要弄明白一点,类都是由元类创建的.在定义类 class Foo:pass的时候(类也是对象),就会执行type类或者type派生类的__init__方法,当Foo()时:执行type类或者ty ...
- SQL 查询语句
4.2 单表查询 4.2.1 列名(表名)的别名(as 可以不加) 给列名取别名既可以加 as 也可以不加. (2008 - Sage.lower(Sdept)等可计算但无列名,需要指定列名) 原列名 ...
- hibernate建表默认为UTF-8编码
一.问题: hibernate自动建表的编码应该是数据默认的编码格式,一般也不是utf-8.所以想要建表默认的编码是UTF-8,应该怎么做呢? 二.解决方法: 拿mysql举例: (一).修改hibe ...
- vue 父组件通过props向子组件传递数据/方法的方式
参考网址:https://segmentfault.com/a/1190000010507616 下面栗子中, callback是传递父组件的方法, mutationName是传递父组件的数据, Ap ...
- jstack Dump 日志文件中的线程状态
[转]jstack Dump 日志文件中的线程状态 dump 文件里,值得关注的线程状态有: 死锁,Deadlock(重点关注) 执行中,Runnable 等待资源,Waiting on condi ...
- python 豆瓣验证码识别总结
总结: pytesseract 识别比较标准的图片 识别成功率 还是不错的. 验证码的图片识别 需要先处理好 再用pytesseract 识别 from PIL import Image ...