题意:给你一串长度为n的数,这个数可以将后面的数挪到前面来,如果没有小于最开始的那个数的话就输出YES,否则输出NO

题解:如果后面有数字小于第一个数的话就肯定是NO了,这题的坑点就是如果前面很长一串都相同但是后面有一个比前面相同位置的数小的话也要输出NO,因为n是5e5,我们不可能检查每一个串,其实对于这个字符串,我们可以求出这个数的最小表示法的答案,如果这个字符串的最小表示法的第一个字符不是第一个的话就是NO了】

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
LL read() {
int x = , f = ; char ch = getchar();
while(ch < '' || ch > '') {
if(ch == '-')f = -;
ch = getchar();
}
while(ch >= '' && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = 1e6 + ;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f; int n;
char s[maxn]; int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
scanf("%d", &n); scanf("%s", s + );
for(int i = ; i <= n; i++) {
s[i + n] = s[i];
}
bool flag = ;
for(int i = ; i <= n; i++) {
if(s[i] < s[]) {
flag = ;
break;
}
}
if(flag) {
cout << "NO" << endl;
} else {
int i = , j = , k;
while(i <= n && j <= n) {
for(k = ; k <= n && s[i + k] == s[j + k]; k++);
if(k == n) break;
if(s[i + k] > s[j + k]) {
i = i + k + ;
if(i == j)i++;
} else {
j = j + k + ;
if(i == j) j++;
}
}
int ans = min(i, j);
if(ans != ) cout << "NO" << endl;
else cout << "YES" << endl;
}
return ;
}

最大最小表示法模板

int getMin() {
int i = , j = ;
int l;
while (i < len && j < len) {
for (l = ; l < len; l++)
if (str[(i + l) % len] != str[(j + l) % len]) break;
if (l >= len) break;
if (str[(i + l) % len] > str[(j + l) % len]) {
if (i + l + > j) i = i + l + ;
else i = j + ;
}
else if (j + l + > i) j = j + l + ;
else j = i + ;
}
return i < j ? i : j;
} int getMax() {
int i = , j = , k = ;
while (i < len && j < len && k < len) {
int t = str[(i + k) % len] - str[(j + k) % len];
if (!t) k++;
else {
if (t > ) {
if (j + k + > i) j = j + k + ;
else j = i + ;
}
else if (i + k + > j) i = i + k + ;
else i = j + ;
k = ;
}
}
return i < j ? i : j; }

Ugly Number Gym - 101875B (最小表示法)的更多相关文章

  1. HDU 4162 Shape Number (最小表示法)

    题意:给你一串n个数,求出循环来看一阶差的最小字典序:数字串看成一个顺时针的环,从某一点开始顺时针循环整个环,保证字典序最小就是答案 例如给你 2 1 3 就会得到(1-2+8 注意题意负数需要加8) ...

  2. HDU 4162 Shape Number(字符串,最小表示法)

    HDU 4162 题意: 给一个数字串(length <= 300,000),数字由0~7构成,求出一阶差分码,然后输出与该差分码循环同构的最小字典序差分码. 思路: 第一步是将差分码求出:s[ ...

  3. [coj 1353 Guessing the Number]kmp,字符串最小表示法

    题意:给一个字符串,求它的最小子串,使得原串是通过它重复得到的字符串的一个子串. 思路:先求最小长度,最小循环长度可以利用kmp的next数组快速得到,求出长度后然后利用字符串最小表示法求循环节的最小 ...

  4. [LeetCode] Ugly Number II 丑陋数之二

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  5. [LeetCode] Ugly Number II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  6. 【LeetCode】264. Ugly Number II

    Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose ...

  7. 313. Super Ugly Number

    题目: Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose ...

  8. [LeetCode] Super Ugly Number (Medium)

    Super Ugly Number 最后WA没做出来. typedef long long int64; #define MAXBOUND 10000000 class Solution { publ ...

  9. Ugly Number II 解答

    Question Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime ...

随机推荐

  1. 百度网盘无vip高速下载的方法

    我拿的是谷歌浏览器做实验 首先下载一个可以改user-agent的插件 我chorm里面下载的是User-Agent Switcher for Chrome插件 将百度网盘的url地址中的baidu. ...

  2. 快速搭建一个基于react的项目

    最近在学习react,快速搭建一个基于react的项目 1.创建一个放项目文件夹,用编辑器打开 2.打开集成终端输入命令: npm install -g create-react-app 3. cre ...

  3. vjudge 骨牌覆盖

    原题链接:https://vjudge.net/contest/331993#problem/B 在2*N的一个长方形方格中,用一个1*2的骨牌排满方格. 问有多少种不同的排列方法. 例如:2 * 3 ...

  4. PHP返回json数据为null

    文件编码非utf-8,导致json_encode()返回false:最后前台ajax接收不到数据

  5. (四)tensorflow-基础(数据类型,张量操作,数学运算)

    摘要: 1.数据类型:标量.向量.矩阵.张量  :数值精度:变量(张量) 2.张量操作:索引.切片.维度操作 3.数学运算:加减乘除(整除和余除):乘方(平方.开方.指数):自然底对数(任意底对数需要 ...

  6. AntDesign(React)学习-7 Menu添加事件

    今天花了大半天时间从老家回到工作地,路上因为肺炎封堵挺厉害,希望国家挺过这个难关,要不大家都失业可就惨了,上一篇做了一个展示数据的demo,这一篇研究antd Menu item点击事件 1.还是先看 ...

  7. Homebrew安装Mysql后的两步必要的命令

    linxmousedeiMac:~ linxmouse$ mysql.server start Starting MySQL .. SUCCESS! linxmousedeiMac:~ linxmou ...

  8. js中的闭包理解

    闭包是一个比较抽象的概念,尤其是对js新手来说.书上的解释实在是比较晦涩,对我来说也是一样. 但是他也是js能力提升中无法绕过的一环,几乎每次面试必问的问题,因为在回答的时候.你的答案的深度,对术语的 ...

  9. 题解【洛谷P1725】琪露诺

    题面 典型的单调队列优化\(\text{DP}\)题. 不难想到设\(dp_i\)表示以\(i\)结尾能得到的最大冰冻指数. 这样设的转移方程也很简单:\(dp_i=\max\left\{ dp_j+ ...

  10. SSM-整合简单配置

    首先说明Spring和Mybatis的版本: Spring:3.2.4 Mybatis:3.3.0 使用了C3P0连接池和Log4J日志,下面是jar包总览: 然后是项目目录总览: 为了能够让项目跑一 ...