ZOJ 3818 Pretty Poem

暴力模拟

细节处理很重要。。。

  1 #include <iostream>
  2 #include <cstring>
  3 #include <cstdio>
  4 using namespace std;
  5
  6     char s1[100],s[100];
  7         int len1,len;
  8     int t;
  9     char a[55],b[55],c[55];
 10
 11 int solved1 (int l,int len){
 12     int temp=0,j;
 13     for (int i=1;i*3<=len;i++){
 14         if ((len-i*3)%2||len<=i*3)
 15             continue ;
 16         j=(len-i*3)/2;
 17         if (i==j){
 18             int flag=1;
 19             for (int z=0;z<i;z++)
 20                 if (s[l+z]!=s[l+z+i]){
 21                     flag=0;
 22                     break ;
 23                 }
 24             if (flag)
 25                 continue ;
 26         }
 27         temp=1;
 28         for (int z=0;z<i+j+i;z++)
 29             if (s[l+z]!=s[l+z+i+j]){
 30                 temp=0;
 31                 break ;
 32             }
 33         if (temp)
 34             return temp;
 35     }
 36     return temp;
 37 }
 38 int solved2 (int l,int len){
 39     int temp=0;
 40     int j,k;
 41     for (int i=1;i*3<=len;i++){
 42         for (int j=1;(j+i)*3<=len;j++){
 43             if (len<=(i+j)*3)
 44                 continue ;
 45             if (i==j){
 46                 int flag=1;
 47                 for (int z=0;z<i;z++)
 48                     if (s[l+z]!=s[l+z+i]){
 49                         flag=0;
 50                         break ;
 51                     }
 52                 if (flag)
 53                     continue ;
 54             }
 55             k=len-3*(i+j);
 56             if (k==i){
 57                 int flag=1;
 58                 for (int z=0;z<i;z++)
 59                     if (s[l+z]!=s[l+z+i+i+j+j]){
 60                         flag=0;
 61                         break ;
 62                     }
 63                 if (flag)
 64                     continue ;
 65             }
 66             if (k==j){
 67                 int flag=1;
 68                 for (int z=i;z<i+j;z++)
 69                     if (s[l+z]!=s[l+z+j+i+j]){
 70                         flag=0;//cout<<z<<" "<<z+k<<endl;
 71                         break ;
 72                     }
 73                 if (flag)
 74                     continue ;
 75             }
 76             temp=1;
 77             for (int z=0;z<i+j;z++)
 78                 if (s[l+z]!=s[l+z+i+j]||s[l+z]!=s[l+z+i+j+i+j+k]){
 79                     temp=0;
 80                     break ;
 81                 }
 82             if (temp)
 83                 return temp;
 84         }
 85     }
 86     return temp;
 87 }
 88
 89 int solved (){
 90     return solved1(0,len)+solved2(0,len);
 91 }
 92
 93 int main (){
 94     cin>>t;
 95     while (t--){
 96         //cin.ignore ();
 97         cin>>s1;
 98         len1=strlen (s1);
 99         len=0;
100         memset (s,‘\0‘,sizeof s);
101         for (int i=0;i<len1;i++)
102             if ((s1[i]>=‘a‘&&s1[i]<=‘z‘)||(s1[i]>=‘A‘&&s1[i]<=‘Z‘)){
103                 s[len++]=s1[i];
104             }//cout<<len<<" "<<s<<endl;
105             //if (solved1()) cout<<"1"<<endl;
106         if (solved())
107             printf ("Yes\n");
108         else printf ("No\n");
109     }
110     return 0;
111 }
时间: 2024-12-25 17:12:29

ZOJ 3818 Pretty Poem的相关文章

zoj 3818 Pretty Poem (模拟)

ZOJ Problem Set - 3818 Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM

zoj 3818 Pretty Poem(暴力处理字符串)2014年牡丹江赛区网络赛

Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can e

ZOJ 3818 Pretty Poem (暴力模拟 string(substr))

Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can e

[ACM] zoj 3818 Pretty Poem (2014 ACMICPC Regional 牡丹江站网络赛 J题)

Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can e

ZOJ 3818 Pretty Poem 模拟题

题目链接:点击打开链接 #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 55; char a[N], b[N]; int main() { int T; scanf("%d", &T); while(T-- > 0) { scanf("%s

【瞎搞】ZOJ 3818 Pretty Poem 牡丹江网络赛J题

第一种情况:ABABA. 先判断开头的A与结尾的A,得到A的长度,接着判断ABAB 中的AB与AB是否相同(ABAB的长度一定为偶数) 已经知道了A长度,AB的长度 接着判断下A 与B是否相同 第二种情况:ABABCAB-可先讲AB看成整体即DDCD 若存在一个D满足条件 可得到C的长度和位置再判断A-B是否相同A-C是否相同 B-C是否相同(暴力取A的长度咯) #include <stdio.h> #include <string.h> #include <stdlib.h

zoj 3818 Pretty Poem(模拟)

# include <stdio.h> # include <algorithm> # include <string.h> # define MAX 55 using namespace std; int L; char a[MAX]; int vis[MAX]; int judge1()//ababa { int i,j; int xx,yy,zz; char x[MAX],y[MAX],z[MAX]; for(i=2; i*2<L; i++) { for(j

ZOJ 3818 Pretty Poem (2014年牡丹江赛区网络赛J题)

1.题目描述:点击打开链接 2.解题思路:本题是一道模拟题,输入一个串,要求判断是否形如"ABABA"或"ABABCAB".只需要对两种情况逐一尝试即可.然而这道题有诸多细节需要考虑.这里说一下我自己的方法. 首先,如果输入的串长度<5,那么直接输出No,或者去掉所有的标点后发现长度<5,输出No.长度上没问题后,写一个专门的solve(int type)函数,来判断是否是上述情况中的一种.对于第一种,只需要枚举A的长度即可,B的长度就是(len-3*i

ZOJ Problem Set - 3818 Pretty Poem

水题 . #include<bits/stdc++.h> using namespace std; int T,n; char buf[55]; string s; bool ok = false; bool ok1(int a,int b) { string s1,s2; s1 = s.substr(0,a); s2 = s.substr(a,b); string buf; if(s1 == s2) return false; buf = s.substr(a+b,a); if(buf !=