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 重复,使得之前的红色部分向后挪一位。于是,我们可以用这一规律去构造出我们想要的k,显然答案就是末尾部分的01(蓝色部分111...10111...10111)满足 num[0]+num[1]==k-1 ,那么对中间的影响(绿色部分111...1011111...110111)往后挪一位也就是我们的答案 k ,最后就是算出这形如 abab 字符串 a 部分中的 1 的个数有多少就行了,设 x 为 a 中 1 的个数,方程为 2*x+1+k-1=n  ,化简为 x=(n-k)/2 ,根据题意 n 与 k 同奇偶,那么 x 也是唯一确定的,最后构造也由此生成。

 1 //      ——By DD_BOND
 2
 3 //#include<bits/stdc++.h>
 4 #include<functional>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<sstream>
 8 #include<iomanip>
 9 #include<climits>
10 #include<cstring>
11 #include<cstdlib>
12 #include<cstddef>
13 #include<cstdio>
14 #include<memory>
15 #include<vector>
16 #include<cctype>
17 #include<string>
18 #include<cmath>
19 #include<queue>
20 #include<deque>
21 #include<ctime>
22 #include<stack>
23 #include<map>
24 #include<set>
25
26 #define fi first
27 #define se second
28 #define MP make_pair
29 #define pb push_back
30 #define INF 0x3f3f3f3f
31 #define pi 3.1415926535898
32 #define lowbit(a)  (a&(-a))
33 #define lson l,(l+r)/2,rt<<1
34 #define rson (l+r)/2+1,r,rt<<1|1
35 #define Min(a,b,c)  min(a,min(b,c))
36 #define Max(a,b,c)  max(a,max(b,c))
37 #define debug(x)  cerr<<#x<<"="<<x<<"\n";
38
39 using namespace std;
40
41 typedef long long ll;
42 typedef pair<int,int> P;
43 typedef pair<ll,ll> Pll;
44 typedef unsigned long long ull;
45
46 const ll LLMAX=2e18;
47 const int MOD=1e9+7;
48 const double eps=1e-8;
49 const int MAXN=1e6+10;
50 const int hmod1=0x48E2DCE7;
51 const int hmod2=0x60000005;
52
53 inline ll sqr(ll x){ return x*x; }
54 inline int sqr(int x){ return x*x; }
55 inline double sqr(double x){ return x*x; }
56 ll __gcd(ll a,ll b){ return b==0? a: __gcd(b,a%b); }
57 ll qpow(ll a,ll n){ll sum=1;while(n){if(n&1)sum=sum*a%MOD;a=a*a%MOD;n>>=1;}return sum;}
58 inline int dcmp(double x){    if(fabs(x)<eps) return 0;    return (x>0? 1: -1); }
59
60 int main(void)
61 {
62     ios::sync_with_stdio(false);    cin.tie(0);   cout.tie(0);
63     int n,k;    cin>>n>>k;
64     for(int i=0,j=(n-k)/2;i<n;i++){
65         if(j)   cout<<1,j--;
66         else cout<<0,j=(n-k)/2;
67     }
68     return 0;
69 }

原文地址:https://www.cnblogs.com/dd-bond/p/10858347.html

时间: 2024-08-30 18:05:23

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

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 <stri

codeforces 848B - Rooter&#39;s Song(构造+几何)

原题链接:http://codeforces.com/problemset/problem/848/B 题意:好多个人分别从x,y轴不同位置不同时间往垂直坐标轴方向移动,一旦相遇他们转向,问所有人的到达边缘的位置. 思路:即使相遇后没有改变方向,终点位置还是不变的. 1.首先可以根据开始移动的时间将每个人的初始位置往后移动ti单位,这样就可以看作所有人都同时开始移动了. 2.接下来,假设两个人i,j在t时刻(x, y)处相撞,那么可以推知两个人的初始位置分别为(x-t, y),(x, y-t),

codeforces 459C - Pashmak and Buses 【构造题】

题目:codeforces 459C - Pashmak and Buses 题意:给出n个人,然后k辆车,d天时间,然后每天让n个人选择坐一辆车去上学,要去d天不能有任意两个人乘同一辆车,不能的话输出 -1 分类:数学,构造 分析:这个题目首先得分析,我开始想到的是首先用相同的放在一起,比如 7 2 3 这样构造 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 就是需要的天数跟每一行出现次数最多的数的出现次数相等,但是发现还有更优

Codeforces 12E Start of the season 构造 一个n*n矩阵使得每行恰好有一个[0,n-1]且对称

题目链接:点击打开链接 题意: 给定一个n 构造 一个n*n矩阵使得每行恰好有一个[0,n-1]且关于主对角线对称 且主对角线必须全为0 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #inc

Codeforces Gym 100187K K. Perpetuum Mobile 构造

K. Perpetuum Mobile Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/K Description The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main part is the energy generator whic

Codeforces 460D Little Victor and Set(构造)

题目链接:Codeforces 460D Little Victor and Set 题目大意:给定范围l,r,选小于k个数,使得这些数的亦或和最小. 解题思路:加入k为偶数,那么kXOR(k+1)=1 根据这个可以处理掉k≠3的所有情况. 对于k=3的情况,找到一个大于l的2k,如果满足2k+1≤r,那么就可以构造出三个数亦或值为0的情况. #include <cstdio> #include <cstring> #include <algorithm> using

codeforces 848A - From Y to Y(构造)

原题链接:http://codeforces.com/problemset/problem/848/A 题意:让我们构造一个字符串.这里有一种操作:取走这个字符串的若干部分,分成两部分,然后将这两部分的合并插回字符串中,进行过处理的字符串部分不能再次被单独取出,只能整体取出,直到无法操作后停止.每次这种操作后,消耗, f(s,c)是c字符在s字符串重复的次数. 让我们输出:若干次操作后最小值恰好为k的字符串,不用考虑字符的顺序. 思路:最好怎么简单怎么做.如果我们让字符串中只有一种字符,显然通过

Codeforces 610C:Harmony Analysis(构造)

[题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样一个矩阵,右下角四分之一和其余三个分块相反, 不断扩展这个矩阵即可. [代码] #include <cstdio> #define rep(i,n) for(int i=1;i<=n;i++) using namespace std; const int N=1000; int k,p[N]

CodeForces 468A. 24 Game(数学构造)

题目链接:http://codeforces.com/problemset/problem/468/A A. 24 Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little X used to play a card game called "24 Game", but recently he has f