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. RedHat/CentOS根目录扩容

    下面以redhat为例,介绍如何扩容系统根目录,CentOS也是一样的. 1. 登录到系统中,查看硬盘情况. /dev/sdb就是增加的硬盘. [root@test ~]# fdisk -l 2. 操 ...

  2. Robot Framework 三种测试用例模式

    1.三种测试用例模式 关键字驱动(keyword-driver).数据驱动(data-driver).行为驱动模式(behavior-driver) 2.关键字驱动(keyword-driver)   ...

  3. Android DatePickerDialog 使用方法

    (一)在Android 4.0以上系统的某些手机(如本人的测试机红米Note(系统4.4.4),以及模拟器(系统4.0)),使用如下代码创建时间选择器时,页面效果如图: Calendar cal = ...

  4. jquery快速获得url 的get传值

    <script> var res = location.search.substr(1).split("&"); var arr={}; for (var i ...

  5. GIL锁,线程池

    内容梗概: 1.线程队列 2.线程池 3.GIL锁 1.线程队列 1.1先进先出队列(FIFO)import queueq = queue.Queue(3)q.put(1)q.put(2)q.put( ...

  6. JavaScript基础一

    1.1 javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) J ...

  7. hbase安装部署

    hbase的安装 ①cp /mnt/hgfs/xiazai/hbase-1.2.5-bin.tar.gz /data tar -xzvf  hbase-1.2.5-bin.tar.gz ②环境 sud ...

  8. java把13位时间戳转换成"yyyy-MM-dd HH:mm:ss"格式,工具类

    public static void main(String[] args) { String time = System.currentTimeMillis();//获取当前时间精确到毫秒级的时间戳 ...

  9. WebSphere静默安装教程(WAS6.1为例)

    1.安装WebSphere 解压守装包: tar -zxf was_soft_64-bit.tar.gz 进入解压出的WAS目录编缉responsefile.nd.txt,将对应选项修值改成以下模样( ...

  10. python截取字符串

    str = ‘0123456789’ print str[0:3] #截取第一位到第三位的字符 print str[:] #截取字符串的全部字符 print str[6:] #截取第七个字符到结尾 p ...