HDU4162 Shape Number(最小表示法)
来源:互联网 发布:go开头的软件 编辑:程序博客网 时间:2024/05/17 00:12
题意:给一个串s1,只包含0到7,用它构造出一个新串s2,输出新串循环移位可以得到的最小串。构造方式:s2[i] = s1[i+1] - s1[i].如果得到的新值小于0,那么就要加8.最后一位要用第一位来减。
思路:构造出新串之后最小表示法求解即可。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<vector>#include<map>#include<algorithm>using namespace std;const int inf = 0x3f3f3f3f;const int mod = 1000000007;const int maxn = 300005;typedef long long ll;int MINR(char s[], int l){for(int i=0; i<l; ++i){s[l + i] = s[i];}s[2 * l] = 0;int i = 0, j = 1;while(i < l && j < l){int k = 0;while(s[i + k] == s[j + k] && k < l){++k;}if(k == l) break;if(s[i + k] > s[j + k]) i = max(i + k + 1, j + 1);else j = max(j + k + 1, i + 1);}return i < j ? i : j;}char s1[maxn], s2[maxn * 2];int main(){ while(~scanf("%s", s1)){ int len = strlen(s1); for(int i=0; i<len; ++i){ if(i == len - 1){ s2[i] = (s1[0] - s1[i] + 8) % 8 + '0'; } else { s2[i] = (s1[i + 1] - s1[i] + 8) % 8 + '0'; } } int pos = MINR(s2, len); for(int i=0; i<len; ++i){ printf("%c", s2[i + pos]); } printf("\n"); } return 0;}
阅读全文
0 0
- HDU4162 Shape Number(最小表示法)
- HDU4162 Shape Number 最小表示法
- hdu4162(最小表示法)
- HDU4162 Shape Number
- HDOJ 4162 Shape Number(最小表示法 )
- hdu 4162 Shape Number(最小表示法)
- HDU 4162 Shape Number(字符串,最小表示法)
- 【最小表示法】HDU-4162-Shape Number
- HDU 4162 Shape Number 最小表示法
- HDU 4162 Shape Number(最小表示法)
- TOJ 3771 HDU 4162 Shape Number / 最小表示法
- 【HDU 4162】Shape Number(一阶差分链码+最小表示法)
- HDU NO.4162 Shape Number(最小表示法循环输出字符串)
- hdu 4162 Shape Number【循环字符串最小表示法】模板学习
- HDU——4162Shape Number(字符串的最小表示)
- 【最小表示法】HDU4162Shape Number
- hdu2609(最小表示法)
- sgu232(最小表示法)
- Unable to instantiate applicatio
- mongo 搭建 replica set
- Unity_往复运动_057
- 从NoSuchMethodError看jvm编译和class加载方式
- nmcli的设备和连接
- HDU4162 Shape Number(最小表示法)
- NOIP训练测试3(2017081601)
- Java实现双向链表/双端链表
- 工厂解耦
- Spring乱码问题解决方案
- 配置Service.xml
- Squid代理服务器
- 拓扑排序例题 hdu1285 hdu3342
- JAVA学习笔记_真假分页查询