The minimal unique substring CodeForces - 1159D (构造)

核心观察是形如01,001,0001,...的串循环时, $n$每增长1, $k$就增长1.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl ‘\n‘
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<‘ ‘;hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<‘0‘||p>‘9‘)p=getchar();while(p>=‘0‘&&p<=‘9‘)x=x*10+p-‘0‘,p=getchar();return x;}
//head

const int N = 1e6+10;
int n, k;
char s[N];

int main() {
	cin>>n>>k;
	int x = (n-k)/2;
	REP(i,1,n) {
		if (x) putchar(‘0‘),--x;
		else putchar(‘1‘),x=(n-k)/2;
	}hr;
}

原文地址:https://www.cnblogs.com/uid001/p/10872677.html

时间: 2024-08-30 15:00:00

The minimal unique substring CodeForces - 1159D (构造)的相关文章

Codeforces 1159D The minimal unique substring(构造)

首先我们先观察三个串 1010,110110,11101110,答案都是红色部分,我们可以下一个结论,形如 abab ( a 中有非负整数个 1 , b 中只有一个 0 )这类的字符串答案恒为 2 ,也就是 k==2 ,然后就是用这类字符串去构造出我们所需的 k .我们可以尝试从末尾加一个1,那么之前的串变成了 10101,1101101,111011101,那么答案为红色部分.我们可以发现,通过我们末尾添加的1,导致之前红色部分的 01 与我们末尾添加的1与前面一个0构成的 01 重复,使得之

B - Save the problem! CodeForces - 867B 构造题

B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错了... 用1 2 来构造 可以先枚举一些数来找找规律. 1 1 2 2 3 1 1 1    2 1 1 4 .... 可以发现每一个数都是 n/2+1 的可能, 所以反过来推过去就是 (s-1)*2  或者(s-1)*2+1 这个(s-1)*2+1的答案才是正确答案 因为 这个s可以==1 #i

Johnny Solving CodeForces - 1103C (构造,图论)

大意: 无向图, 无重边自环, 每个点度数>=3, 要求完成下面任意一个任务 找一条结点数不少于n/k的简单路径 找k个简单环, 每个环结点数小于n/k, 且不为3的倍数, 且每个环有一个特殊点$x$, $x$只属于这一个环 任选一棵生成树, 若高度>=n/k, 直接完成任务1, 否则对于叶子数一定不少于k, 而叶子反向边数>=2, 一定可以构造出一个环 #include <iostream> #include <algorithm> #include <c

Codeforces 1188A 构造

题意:给你一颗树,树的边权都是偶数,并且边权各不相同.你可以选择树的两个叶子结点,并且把两个叶子结点之间的路径加上一个值(可以为负数),问是否可以通过这种操作构造出这颗树?如果可以,输出构造方案.初始树的边权都是0. 思路:A1很简单,只要判断是否有度数为2的点就可以了.对于A2, 由于边权各不相同,所以A1的结论同样适用.现在我们来构造一组答案.官方题解的构造方式是这样的:我们假设要让一个节点u到叶子结点v的路径都加上一个值x,并且知道叶子结点l1, l2都可以到达u,我们执行以下操作:v到l

codeforces 的20道C题

A - Warrior and Archer CodeForces - 595C n  偶数  然后n个数字 A B 轮流取一个 A让差变小B让差变大 直到最后2 个   求的是最小剩下的差 最后剩下的 L R  相距 n/2    求一下最小的就行 #include <iostream> #include <cstdio> #include <cmath> #include <map> #include <algorithm> #include

LeetCode Unique Substrings in Wraparound String

原题链接在这里:https://leetcode.com/problems/unique-substrings-in-wraparound-string/description/ 题目: Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvw

动态规划-独特的子字符串存在于Wraparound String总个数 Unique Substrings in Wraparound String

2018-09-01 22:50:59 问题描述: 问题求解: 如果单纯的遍历判断,那么如何去重保证unique是一个很困难的事情,事实上最初我就困在了这个点上. 后来发现是一个动态规划的问题,可以将每个字符结尾的最长长度进行保存,这样就巧妙的解决的重复的问题. The max number of unique substring ends with a letter equals to the length of max contiguous substring ends with that

#292 (div.2) D.Drazil and Tiles (贪心+bfs)

Description Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should

[训练日志] 7月17-21日

codeforces 351C [构造一个n*m的括号序列,每个位置根据%n的情况(和)分别有花费,求最小费用] [考虑一般dp.有结论状态不会超过n.所以我们以n位为一块,用f[i][k][j]表示目前i位,前缀和最小为k,当前和为j的最小费用,预处理出从状态转移矩阵T.然后用min_plus矩阵加速T^m计算.] [状态不超过2n的证明:在刚到达2n的前一刻的前缀和一定>n,所以可以将之后和为负的块往前调整,使得状态不超过2n] [此题也可考虑倍增, F[k][i][j]表示2^k * n个