HDU 4162 最小表示法
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4162
题意:给定一个只有0-7数字组成的串。现在要由原串构造出一个新串,新串的构造方法:相邻2个位置的数字的差值。若为负数则要加上8,问新构造出来的串的一个字典序最小同构串是什么?
思路:就按照题意构造出新串后,然后就是最小表示法了。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = + ;
typedef long long int LL;
#define INF 0x3f3f3f3f
int MinRepresentation(int *s,int l){
int i = , j = , k = ;
while (i < l&&j < l&&k < l){
int li, lj;
li = (i + k) >= l ? i + k - l : i + k;
lj = (j + k) >= l ? j + k - l : j + k;
if (s[li] == s[lj]){
k++;
}
else{
if (s[li]>s[lj]){
i = i + k + ;
}
else{
j = j + k + ;
}
if (i == j){
j++;
}
k = ;
}
}
return i < j ? i : j;
}
int str[MAXN];
char s[MAXN];
int main()
{
while (~scanf("%s", s)){
int len = strlen(s);
for (int i = ; i < len; i++){ //构造新串
if (i == len - ){
str[i] = (((s[] - '') + - (s[i] - '')) % );
}
else{
str[i] = (((s[i+] - '') + - (s[i] - '')) % );
}
}
int start = MinRepresentation(str,len);
for (int i = ; i < len; i++){
printf("%d", str[(start + i) % len]);
}
printf("\n");
}
return ;
}
HDU 4162 最小表示法的更多相关文章
- HDU 2609 最小表示法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题意:给定n个循环链[串],问有多少个本质不同的链[串](如果一个循环链可以通过找一个起点使得和 ...
- String Problem hdu 3374 最小表示法加KMP的next数组
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 4162 Shape Number(字符串,最小表示法)
HDU 4162 题意: 给一个数字串(length <= 300,000),数字由0~7构成,求出一阶差分码,然后输出与该差分码循环同构的最小字典序差分码. 思路: 第一步是将差分码求出:s[ ...
- HDU 4162 Shape Number (最小表示法)
题意:给你一串n个数,求出循环来看一阶差的最小字典序:数字串看成一个顺时针的环,从某一点开始顺时针循环整个环,保证字典序最小就是答案 例如给你 2 1 3 就会得到(1-2+8 注意题意负数需要加8) ...
- HDU 3374 最小/大表示法+KMP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给定一个串s,该串有strlen(s)个循环同构串,要求输出字典序最小的同构串的下标,字典 ...
- hdu String Problem(最小表示法入门题)
hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...
- Hdu 5442 Favorite Donut (2015 ACM/ICPC Asia Regional Changchun Online 最大最小表示法 + KMP)
题目链接: Hdu 5442 Favorite Donut 题目描述: 给出一个文本串,找出顺时针或者逆时针循环旋转后,字典序最大的那个字符串,字典序最大的字符串如果有多个,就输出下标最小的那个,如果 ...
- HDU - 3374 String Problem (kmp求循环节+最大最小表示法)
做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. ...
- Favorite Donut(HDU 5442)最小表示法+二分
题目给出一个字符串,由a~z表示甜度,随字典序增大,字符串首尾相连形成一个圈,要求从一个位置开始字典序最大的字符串,输出位置以及是顺时针还是逆时针表示.顺时针用0表示,逆时针用1表示. 此题只需要查找 ...
随机推荐
- ul 仿 table 循环滚动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【leetcode】Reverse Nodes in k-Group (hard)☆
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...
- Server.Transfer方式(或称HttpContext方式)传值实例
public class QueryPage : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox txtStaDate ...
- September 30th 2016 Week 40th Friday
Elegance is the only beauty that never fades. 优雅是唯一不会褪色的美. Even the most beautiful apperance may los ...
- function与感叹号
原文链接:https://swordair.com/function-and-exclamation-mark/ 最近有空可以让我静下心来看看各种代码,function与感叹号的频繁出现,让我回想起2 ...
- 在程序中使用geos.dll
1 在项目->property->configuration properties->c/c++->general->additional include directo ...
- *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext iOS9.1闪退问题解决
错误原因在于 AppDelegate 中 didFinishLaunchingWithOptions 结束前 未定义 rootViewController,Xcode7规定必须要有rootViewCo ...
- java的system.arraycopy()方法
java.lang.System的静态方法arraycopy()可以实现数组的复制,讲课的老师说这个方法效率比较高,如果数组有成千上万个元素,那么用这个方法,比用for语句循环快不少.于是我试了试,发 ...
- ISD1700系列多段语音录放系列
ISD1700系列语音芯片的基础指示:
- Android -- FragmentActivity添加Fragment的序列图
FragmentActivity添加Fragment的序列图