Problem

题目给出一个加密前的字符串长度为p和加密后的字符串长度为s,让你求一个长度为K字典序最小的密钥。

密钥是循环的,第i位为1表示加密前的第i为是有用的否则是没用的。

Solution

首先枚举秘钥中一共有x个1(1<=x<=min(s,k))

一个秘钥有x个1,也就是能确定加密串每个位置所对应秘钥的第几次循环。

并且贪心从后往前找每一个位置即可。

Notice

容易出错

Code

#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9;
const double eps = 1e-6, phi = acos(-1.0);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
string st1, st2, xx[2005], yy[2005], ans;
int sqz()
{
getline(cin, st1), getline(cin, st2);
int len1 = st1.length(), len2 = st2.length();
int k = read(), t = min(k, len2);
rep(i, 0, len1 - 1) xx[i % k] += st1[i];
ans = "2";
rep(i, 1, t)
{
rep(j, 0, t - 1) yy[j] = "";
rep(j, 0, len2 - 1) yy[j % i] += st2[j];
int now = i; string zz;
per(j, k - 1, 0)
if (now && xx[j] == yy[now - 1])
zz += "1", now--;
else zz += "0";
if (!now)
{
reverse(zz.begin(), zz.end());
ans = min(ans, zz);
}
}
if (ans == "2") ans = "0";
cout << ans << endl;
}

[CodeForces332E]Binary Key的更多相关文章

  1. [CodeForces-332E]Binary Key

    题目大意: 给你两个字符串p和s,让你求出一个字典序尽量小的长度为k的01串密钥,能将p转化为s. 密钥的工作方式如下: 第i位是0,表示这一位无用: 第i位是1,表示这一位有用. 若密钥的长度比s短 ...

  2. php集成动态口令认证

    这篇文章主要为大家详细介绍了php集成动态口令认证,动态口令采用一次一密.用过密码作废的方式来提高安全性能,感兴趣的小伙伴们可以参考一下 大多数系统目前均使用的静态密码进行身份认证登录,但由于静态密码 ...

  3. Flink - Juggling with Bits and Bytes

    http://www.36dsj.com/archives/33650 http://flink.apache.org/news/2015/05/11/Juggling-with-Bits-and-B ...

  4. Load an X509 PEM file into Windows CryptoApi

    http://stackoverflow.com/questions/1231178/load-an-x509-pem-file-into-windows-cryptoapi I discovered ...

  5. TQ210裸机编程(4)——按键(中断法)

    S5PV210有4个向量中断控制器(VIC),每个向量中断控制器包含32个中断源. 当某个中断源产生中断时,CPU会自动的将VICxVECTADDRy(x=0,1,2,3,y=0-31)寄存器的值赋给 ...

  6. TQ210裸机编程(3)——按键(查询法)

    首先查看TQ210的底板原理图 这次编程只操作KEY1和KEY2,在TQ210核心板原理图中搜索XEINT0 可以看出KEY1和KEY2分别接在S5PV210的GPH0_0和GPH0_1引脚. 这次编 ...

  7. SecureCRT辅助解决方案

    SecureCRT辅助解决方案 1. 下载SecureCRT 7.3版本并激活: 2. SecureCRT linux配色方案: 3. SecureCRT设置log保存方案: 1. secureCRT ...

  8. Google Maps API Web Services

    原文:Google Maps API Web Services 摘自:https://developers.google.com/maps/documentation/webservices/ Goo ...

  9. hadoop 测试框架

    hadoop 0.21以前的版本中(这里拿0.20为例,其他版本可能有少许不同),所有的测试相关代码都是放置在${HADOOP_HOME}/src/test下,在该目录下,是按照不同的目录来区分针对不 ...

随机推荐

  1. Linux命令echo

    echo "hello world" echo 显示字符串内容

  2. composer修改中文镜像

    composer config -g repo.packagist composer https://packagist.phpcomposer.com

  3. win10如何一键开启关闭windows Defender(亲测有效)

    win10如何一键开启关闭windows Defender(亲测有效) 一.总结 一句话总结:各种找资料如何开启关闭都没用,直接下载软件简单方便 软件 因为我关windows defender是用的一 ...

  4. (转)C# 单例模式

    文章1:  一.多线程不安全方式实现 public sealed class SingleInstance    {        private static SingleInstance inst ...

  5. python如何判断一个字符串是中文,还是英文。

    参考链接: https://blog.csdn.net/hit0803107/article/details/52885702 decode:  将其它编码转成  ===>unicode enc ...

  6. <property name="hibernate.hbm2ddl.auto">update</property> 问题

    其实这个hibernate.hbm2ddl.auto参数的作用主要用于:自动创建|更新|验证数据库表结构.如果不是此方面的需求建议set value="none".create:每 ...

  7. InitializingBean和DisposableBean

    InitializingBean 记住一点:InitializingBean接口为bean提供了初始化方法的方式,它只包括afterPropertiesSet方法,凡是继承该接口的子类,在初始化bea ...

  8. English Voice of << Count on me >>

    Count On Me 歌手:Bruno Mars 所属专辑:It´s Better If You Don´t Understand If you ever find yourself stuck i ...

  9. Confluence 6 给一个从 Jira Service Desk 的非许可证用户访问权限

    如果你正在使用 Confluence 为 Jira 服务桌面(Jira Service Desk)的知识库,你可以选择允许所有活动的用户和客户(客户是可以登录的用户,但是这些用户是没有 Conflue ...

  10. csu oj 1342: Double

    Description 有一个由M个整数组成的序列,每次从中随机取一个数(序列中每个数被选到的概率是相等的)累加,一共取N次,最后结果能被3整除的概率是多少? Input 输入包含多组数据.     ...