B - Sonya and Exhibition CodeForces - 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 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][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个格子,每个格子里能放一种花,一共有两种花,一种用 0 代表,另一种用 1 代表,然后给你m各区间,每个区间的价值就是这个区间内的两种花的数量之积。问你应该怎么放花,使得这些区间的价值和最大。
分析:
题目的意思转化一下,就是说让0 1 的个数在各个区间内都是接近的(和相等,越接近,积越大),也就是说0 1 分布均匀,那么,我们直接0 1 交替输出,就可以保证0 1 在各个区间都是最接近的。(一开始想了好久,woc,这个放置的方法真的是太绝了,区间根本就是坑啊)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = ; int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<m;i++)
{
int l,r;
scanf("%d%d",&l,&r);
}
for(int i=;i<=n;i++)
{
printf("%d",i%);
}
}
B - Sonya and Exhibition CodeForces - 1004B (思维题)的更多相关文章
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- Vova and Trophies CodeForces - 1082B(思维题)
Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...
- CodeForces - 417B (思维题)
Crash Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- CodeForces - 417A(思维题)
Elimination Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Sonya and Exhibition 1004B
B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CodeForces - 631C ——(思维题)
Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...
随机推荐
- Oracle子查询和多表查询
多表查询需要用到表的连接 连接可以分为:(自行百度) 交叉连接(数字逻辑的笛卡尔积,不做解释) 等值连接 例如:select * from t_a, t_b where t_a.xx = t_b.xx ...
- Maven的学习资料收集--(九) 构建SSH项目以及专栏maven
在这里整合一下,使用Maven构建一个SSH项目 1.新建一个Web项目 可以参照前面的博客 2.添加依赖,修改pom.xml <project xmlns="http://maven ...
- 设计模式--观察者模式(KVO)
观察者模式(Observer):观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 举个例子, ...
- Android客户端与PC服务端、android服务端通过WiFi通信
前期准备:我的是Linux Mint操作系统(总之折腾的过程中怀疑过是不是系统的问题),首先是要创建wifi热点给android手机使用,这个时候笔记本作为通信的服务器端,android手机作为客户端 ...
- XShell远程连接本地虚机
有很多朋友在自己电脑上部署完成了虚机,但是不知道怎么去用工具连接自己的虚机,下面给大家讲一下大概的步骤,不足之处敬请指正!! 1.打开我们的虚拟机平台,登录虚机 2.远程那肯定要知道虚机的IP地址,在 ...
- echarts的title和legend重合解决(各种小细节)
一:关于title与legend重叠 1.重合样子 2.解决办法: legend:{ show: true, top:"6%",//与上方的距离 可百分比% 可像素px }, 3. ...
- php 02
变量的数据类型 一.类型 标量类型: 布尔型 整型 浮点型 字符串 复合类型: 数组 对象 特殊类型: 资源 null 1. 布尔型 true false 以下值认为是false 其他值都认 ...
- 关于com工程依赖的一些总结
作者:朱金灿 来源:http://blog.csdn.net/clever101 一是com组件工程的依赖设置.比如A这个组件工程要使用B组件工程的类,要如何设置呢?具体就是先把在A工程里加上B工程的 ...
- JavaScript获取URL参数公共方法
写一个JavaScript获取URL参数的通用方法,可以把它放到常用方法的JS文件中调用,直接上代码例子,新手可以学习一下! <!DOCTYPE html> <html lang=& ...
- CAD Import .NET支持AutoCAD DWG 2013
CADSoftTools发布了CAD Import .NET 9一个新版本.NET开发库,可以提供给开发人员导入AutoCAD DWG.DXF.HPGL.PLT.CGM等格式的功能. 在新版本中,CA ...