[CodeForces332E]Binary Key
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的更多相关文章
- [CodeForces-332E]Binary Key
题目大意: 给你两个字符串p和s,让你求出一个字典序尽量小的长度为k的01串密钥,能将p转化为s. 密钥的工作方式如下: 第i位是0,表示这一位无用: 第i位是1,表示这一位有用. 若密钥的长度比s短 ...
- php集成动态口令认证
这篇文章主要为大家详细介绍了php集成动态口令认证,动态口令采用一次一密.用过密码作废的方式来提高安全性能,感兴趣的小伙伴们可以参考一下 大多数系统目前均使用的静态密码进行身份认证登录,但由于静态密码 ...
- 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 ...
- Load an X509 PEM file into Windows CryptoApi
http://stackoverflow.com/questions/1231178/load-an-x509-pem-file-into-windows-cryptoapi I discovered ...
- TQ210裸机编程(4)——按键(中断法)
S5PV210有4个向量中断控制器(VIC),每个向量中断控制器包含32个中断源. 当某个中断源产生中断时,CPU会自动的将VICxVECTADDRy(x=0,1,2,3,y=0-31)寄存器的值赋给 ...
- TQ210裸机编程(3)——按键(查询法)
首先查看TQ210的底板原理图 这次编程只操作KEY1和KEY2,在TQ210核心板原理图中搜索XEINT0 可以看出KEY1和KEY2分别接在S5PV210的GPH0_0和GPH0_1引脚. 这次编 ...
- SecureCRT辅助解决方案
SecureCRT辅助解决方案 1. 下载SecureCRT 7.3版本并激活: 2. SecureCRT linux配色方案: 3. SecureCRT设置log保存方案: 1. secureCRT ...
- Google Maps API Web Services
原文:Google Maps API Web Services 摘自:https://developers.google.com/maps/documentation/webservices/ Goo ...
- hadoop 测试框架
hadoop 0.21以前的版本中(这里拿0.20为例,其他版本可能有少许不同),所有的测试相关代码都是放置在${HADOOP_HOME}/src/test下,在该目录下,是按照不同的目录来区分针对不 ...
随机推荐
- 学习笔记5—Python 将多维数据转为一维数组 (总结)
<code class="language-python">import operator from functools import reduce a = [[1,2 ...
- 在cmd中登录MySQL数据库
mysql -uroot -p 输入密码,即可
- Memcached安装&启动
安装 *Linux系统安装memcached,首先要先安装libevent库,安装请指定 --with--libevent=PATH(若安装过程中出现configure: error : no acc ...
- sql 聚合函数和group by 联合使用
原文 很多时候单独使用聚合函数的时候觉得很容易,求个平均值,求和,求个数等,但是和分组一起用就有点混淆了,好记性不如烂笔头,所以就记下来以后看看. 常用聚合函数罗列 1 AVG() - 返回平均值 C ...
- windows下开启端口映射配置办法
#1.添加一个端口映射 netsh interface portproxy add v4tov4 listenaddress=大网IP listenport=端口 connectaddress=要映 ...
- windows/browser ----> cmd命令/powershell命令/chrome插件vimuim命令
windows 7 cmd常用命令: 1.进入某盘,比如d盘:d:(有一个冒号) 2.显示d盘的文件夹和文件:dir 3.进入d盘某个文件夹:cd filename 4.清除屏幕:cls 5.查看ip ...
- LeetCode--458--可怜的小猪
问题描述: 有1000只水桶,其中有且只有一桶装的含有毒药,其余装的都是水.它们从外观看起来都一样.如果小猪喝了毒药,它会在15分钟内死去. 问题来了,如果需要你在一小时内,弄清楚哪只水桶含有毒药,你 ...
- Stanford: Creating a Hadoop-2.x project in Eclipse
Creating a Hadoop-2.x project in Eclipse http://snap.stanford.edu/class/cs246-data-2014/hw0.pdf Hado ...
- CentOS中与网络相关的常用
CentOS中与网络相关的常用配置文件 1. 常见的网络配置文件 /etc/hosts 本地域名解析表,用于解析主机名.对应于win系统中的C:\Windows\System32\ ...
- Watto and Mechanism CodeForces - 514C (字典树,哈希)
大意: 给定字符串集$S$, 每次询问给出字符串$a$, 求$S$中是否存在一个字符串恰好与$a$相差一个字符. 直接建字典树暴力复杂度是$O(n\sqrt{n})$, 也可以用set维护所有哈希值, ...