Ugly Number Gym - 101875B (最小表示法)
题意:给你一串长度为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 (最小表示法)的更多相关文章
- HDU 4162 Shape Number (最小表示法)
题意:给你一串n个数,求出循环来看一阶差的最小字典序:数字串看成一个顺时针的环,从某一点开始顺时针循环整个环,保证字典序最小就是答案 例如给你 2 1 3 就会得到(1-2+8 注意题意负数需要加8) ...
- HDU 4162 Shape Number(字符串,最小表示法)
HDU 4162 题意: 给一个数字串(length <= 300,000),数字由0~7构成,求出一阶差分码,然后输出与该差分码循环同构的最小字典序差分码. 思路: 第一步是将差分码求出:s[ ...
- [coj 1353 Guessing the Number]kmp,字符串最小表示法
题意:给一个字符串,求它的最小子串,使得原串是通过它重复得到的字符串的一个子串. 思路:先求最小长度,最小循环长度可以利用kmp的next数组快速得到,求出长度后然后利用字符串最小表示法求循环节的最小 ...
- [LeetCode] Ugly Number II 丑陋数之二
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- [LeetCode] Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- 【LeetCode】264. Ugly Number II
Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose ...
- 313. Super Ugly Number
题目: Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose ...
- [LeetCode] Super Ugly Number (Medium)
Super Ugly Number 最后WA没做出来. typedef long long int64; #define MAXBOUND 10000000 class Solution { publ ...
- Ugly Number II 解答
Question Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime ...
随机推荐
- python接口自动化-requests-toolbelt处理multipart/form-data
1.requests-toolbelt官方文档:https://pypi.org/project/requests-toolbelt/ 2.环境安装 pip install requests-tool ...
- 【分享】一款特别轻量的gif生成工具
github链接:https://github.com/NickeManarin/ScreenToGif/releases/tag/2.19.3 超级好用!支持多种方式(摄像头也可√)录制gif
- centOS添加ipv6支持(仅限已分配ipv6地址和网关)
https://blog.csdn.net/cnmilan/article/details/8493977 CentOS 环境下 IPv6设置方法: 1)/etc/sysconfig/network ...
- javascript download geoserver layer as kml file
var sqlfilter = " CITY='" + city + "' and SDATE>" + sdate + " and SDATE ...
- arm汇编笔记
ARM汇编(非虫笔记) 1.ARM汇编的目的: 分析elf文件的需要. 2.原生程序生成过程. (1)预处理,编译器处理c代码中的预处理指令. gcc -E hello.c -o hello.i (2 ...
- HashMap源码(一)
本文主要是从学习的角度看HashMap源码 HashMap的数据结构 HashMap是一个数组+链表的结构(链表散列),每个节点在HashMap中以一个Node存在: HashMap的初始化 publ ...
- tp3.2框架关闭日志记录
在config.php中阿计入如下配置: 'LOG_RECORD' => false, // 默认不记录日志 'LOG_TYPE' => 'File', // 日志记录类型 默认为文件方式 ...
- 巨杉Tech|SequoiaDB 巨杉数据库高可用容灾测试
数据库的高可用是指最大程度地为用户提供服务,避免服务器宕机等故障带来的服务中断.数据库的高可用性不仅仅体现在数据库能否持续提供服务,而且也体现在能否保证数据的一致性. SequoiaDB 巨杉数据库作 ...
- 以POST方式发送
URL url = null; String inputLine = null; HttpURLConnection httpurlconnection = null; try { //取上级电警平台 ...
- TD - setAttribute()
添加指定的属性,并为其赋指定的值 this.sltLevelType.setAttribute("height", "100px");