zoukankan      html  css  js  c++  java
  • 备战NOIP——模板复习22

    这里只有模板,并不作讲解,仅为路过的各位做一个参考以及用做自己复习的资料,转载注明出处。

    最小表示法

    /*Copyright: Copyright (c) 2018
    *Created on 2018-11-06
    *Author: 十甫
    *Version 1.0 
    *Title: 最小表示法
    *Time: inf mins
    */
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    const int size = 1e5 + 5;
    
    char str[size];
    
    int main() {
    	scanf("%s", str + 1);
    	int n = strlen(str + 1);
    	memcpy(str + n + 1, str + 1, n);
    	int i = 1, j = 2, k;
    	while(i <= n && j <= n) {
    		for(k = 0;k <= n && str[i + k] == str[j + k];k++);
    		if(k == n) {
    			break;
    		}
    		if(str[i + k] > str[j + k]) {
    			i += k + 1;
    			if(i == j) {
    				j++;
    			}
    		} else {
    			j += k + 1;
    			if(j == i) {
    				i++;
    			}
    		}
    	}
    	int ans = min(i, j);
    	for(int i = ans;i < ans + n;i++) {
    		printf("%c", str[i]);
    	}
    	printf("
    ");
    	return 0;
    }
    NOIP 2018 RP++
  • 相关阅读:
    观察者模式
    工厂模式
    单例模式
    代理模式
    策略模式
    Ioc容器
    Spring概述
    02:入门
    01:背景
    编译原理感悟
  • 原文地址:https://www.cnblogs.com/Black-S/p/9930701.html
Copyright © 2011-2022 走看看