CodeForces - 401C Team(简单构造)
题意:要求构造一个字符串,要求不能有连续的两个0在一起,也不能有连续的三个1在一起。
分析:
1、假设有4个0,最多能构造的长度为11011011011011,即10个1,因此若m > (n + 1) * 2则肯定不能构造成功。
2、假设有4个0,则至少有3个1,若小于3个,则会有两个连续的0在一起,所以n > m + 1则肯定不能构造成功。
3、当n==m+1时,一定是01串。
4、当m>=n时,应以1为开头构造,根据m和n的个数决定放1个1还是2个连续的1。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
int n, m;
scanf("%d%d", &n, &m);
if(n > m + 1 || m > (n + 1) * 2){
printf("-1\n");
}
else if(n == m + 1){
for(int i = 0; i < m; ++i){
printf("01");
}
printf("0\n");
}
else{
while(n > 0 || m > 0){
if(n == m){
if(m){
printf("1");
--m;
}
}
else{
if(m >= 2){
printf("11");
m -= 2;
}
else if(m == 1){
printf("1");
--m;
}
}
if(n){
printf("0");
--n;
}
}
printf("\n");
}
return 0;
}
CodeForces - 401C Team(简单构造)的更多相关文章
- Codeforces 401C Team 贪心法
本题使用贪心法.关键是考贪心策略.同一时候要求要细心,我提交的时候也WA了几次.大意题目就是怎样依照给定的规则排列一个01字符串,引用原题例如以下: C. Team time limit per te ...
- codeforces 932E Team Work(组合数学、dp)
codeforces 932E Team Work 题意 给定 \(n(1e9)\).\(k(5000)\).求 \(\Sigma_{x=1}^{n}C_n^xx^k\). 题解 解法一 官方题解 的 ...
- Codeforces 932E Team work 【组合计数+斯特林数】
Codeforces 932E Team work You have a team of N people. For a particular task, you can pick any non-e ...
- Codeforces 410C.Team[构造]
C. Team time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Yet Another Ball Problem CodeForces - 1118E (简单构造)
大意: 求构造n个pair, 每个pair满足 对于每k组, 让$b_i$为$[1,k]$, $g_i$循环右移就好了 int n, k, cnt; int main() { scanf(" ...
- codeforces 108D Basketball Team(简单组合)
D. Basketball Team time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 107B Basketball Team 简单概率
题目链接:点击打开链接 题意: 给定n m h 表示有m个部门,有个人如今在部门h 以下m个数字表示每一个部门的人数.(包含他自己) 在这些人中随机挑选n个人,问挑出的人中存在和这个人同部门的概率是多 ...
- Codeforces 1383D - Rearrange(构造)
Codeforces 题面传送门 & 洛谷题面传送门 一道不算困难的构造,花了一节英语课把它搞出来了,题解简单写写吧( 考虑从大往小加数,显然第三个条件可以被翻译为,每次加入一个元素,如果它所 ...
- codeforces 757F Team Rocket Rises Again
链接:http://codeforces.com/problemset/problem/757/F 正解:灭绝树. mdzz倍增lca的根节点深度必须是1..我因为这个错误调了好久. 我们考虑先求最短 ...
随机推荐
- Django:邮件功能实现
django-users2和django的邮件功能模块都有相关的实现 ----------------------------------------------------------------- ...
- 解决css中display:inline-block的兼容问题
*display:inline; *zoom:1; 不多说,ie6/7直接在元素添加以上的属性即可.
- 输入、输出(iostream)
在一个程序当中输入和输出都扮演着重要的角色,所以掌握基本输入输出是入门一门语言所必不可少的.本文主要简单叙述java的输入和输出. package ios; import java.util.Scan ...
- 1-6SpringBoot之事务管理@Transactional
以前学ssh ssm都有事务管理service层通过applicationContext.xml配置,所有service方法都加上事务操作: 用来保证一致性,即service方法里的多个dao操作,要 ...
- angularJS MVVM
- 小程序canvas 变换
var ctx = wx.createCanvasContext('base'); var centerX = 375/ 2; var centerY = 200; var rotate = 90; ...
- Linux打印变量、环境配置、别名和文件删除操作
一.打印命令 1.echo打印命令 a.打印环境变量 echo $Path b.打印Path命令目录 which,比如:which ls表示打印的是Path目录中第一定义的全局变量的目录中命令. 二. ...
- gitlab clone或者pull 仓库
今天在学git操作,想从gitlab上面clone下来并操作一下,但是一直出现 没有权限的错误,一直搞不定 后来才知道,需要ssh密钥才可以 ssh-keygen -t rsa -C "ex ...
- Elasticsearch的快速使用——Spring Boot使用Elastcisearch, 并且使用Logstash同步mysql和Elasticsearch的数据
我主要是给出一些方向,很多地方没有详细说明.当时我学习的时候一直不知道怎么着手,花时间找入口点上比较多,你们可以直接顺着方向去找资源学习. 如果不是Spring Boot项目,那么根据Elastics ...
- firewalld学习--service的使用和配置
service配置文件 firewalld默认给我们提供的ftp的service配置文件ftp.xml <?xml version="1.0" encoding=" ...