【玲珑杯 1054】【暴力+枚举约数】String cut

传送门:http://www.ifrog.cc/acm/problem/1054

思路:

首先知道这样一个性质,删除一个字符之后的字符串的循环节长度一定是nn的约数。所有我们就枚举删除哪一个字符,然后对每一个约数判断是否可以循环节为它。复杂度O(nlogn)


代码:

#include 
#include  
#include 
#include 
using  namespace  std;

#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rrep(i,k,n) for(int i=k;i>=n;i--)
#define pl(x) cout << #x << "= " << x << endl;

template void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
const int N=1e5+10;
string s;

int  main(){
  int T;
  read(T);
  while(T--){
    int n;
    read(n);
    // if(n==1) return 0*puts(0);
    cin>>s;
    int mx=0;
    rep(i, 0, n-1){
      string ss = s.substr(0, i);
      ss = ss+s.substr(i+1, n-i);
      // cout<<"ss="<


描述:

1054 - String cut

Time Limit:4s Memory Limit:64MByte

Submissions:151Solved:54

DESCRIPTION

A string cut cc means the string can be divided into cc same substring. Such as string: abababababab.Because it can be divied into abab + abab + abab, the string cut of it is 33.
Give you a string strstr.you need to delete one char of it ,and after your operation the string cut of it will be biggest.Print the biggest string cut.

INPUT
There are multiple test cases.The first line is a number T ( T 10T ≤10), which means the number of cases.For each case, a line has a integer n(1<=n<=100001)n(1<=n<=100001),which is the length of string.next line a string str str (which just include lowercase).
OUTPUT
one line --- the biggest string cut.
SAMPLE INPUT
23aab5aabaa
SAMPLE OUTPUT
24
SOLUTION
“玲珑杯”ACM比赛 Round #4

你可能感兴趣的:(online,judge,玲珑杯,------暴力)