• BZOJ2295: 【POJ Challenge】我爱你啊


    2295: 【POJ Challenge】我爱你啊

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 126  Solved: 90
    [Submit][Status]

    Description

    ftiasch是个十分受女生欢迎的同学,所以她总是收到许多情书。虽然她十分有魅力,然而她却是个低调的人。因此她从来不会告诉别人她到底收到了多少情书。

    ftiasch的好朋友1tthinking想知道她到底收到了多少情书。1tthinking知道,ftiasch每次收到一封情书,就会在日记 最后写下一个包含"luvletter"子序列的串。比如现在ftiasch的日记是alduddvdletterflusvletetedr,那么 ftiasch可能受到了0、1、2封情书。现在给出一些ftiasch的日记,问对于每篇日记,ftiasch最多可能受到多少的情书。

    某个序列的子序列是从最初序列通过去除某些元素但不破坏馀下元素的相对位置而形成的新序列。參考wikipedia

    Input

    第1行,一个整数 T (0 ≤ T ≤ 100), 日记的数量。

    第2到 T + 1行,ftiasch的日记 (只包含'a'-'z' 和空格, 长度小于100001)

    Output

    第1到T行,一个整数, 最大可能的情书数量。

    Sample Input

    5
    t
    llllluvletterrr
    luvletterlauavalaeatataearaluvletter
    is wzk a famous boy yes buz he always receives a lot of luv letters
    my heart beats her waves at the shore of the world and writes upon it her signature in tears with the words i love thee

    Sample Output

    0
    1
    3
    1
    0

    HINT

    Source

    题解:
    给题面点个赞!
    刚开始看成DP了,后来发现直接模拟匹配就可以了。。。
    代码:
     1 #include<cstdio>
     2 
     3 #include<cstdlib>
     4 
     5 #include<cmath>
     6 
     7 #include<cstring>
     8 
     9 #include<algorithm>
    10 
    11 #include<iostream>
    12 
    13 #include<vector>
    14 
    15 #include<map>
    16 
    17 #include<set>
    18 
    19 #include<queue>
    20 
    21 #include<string>
    22 
    23 #define inf 1000000000
    24 
    25 #define maxn 100000
    26 
    27 #define maxm 500+100
    28 
    29 #define eps 1e-10
    30 
    31 #define ll long long
    32 
    33 #define pa pair<int,int>
    34 
    35 #define for0(i,n) for(int i=0;i<=(n);i++)
    36 
    37 #define for1(i,n) for(int i=1;i<=(n);i++)
    38 
    39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    40 
    41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    42 
    43 #define mod 1000000007
    44 
    45 using namespace std;
    46 
    47 inline int read()
    48 
    49 {
    50 
    51     int x=0,f=1;char ch=getchar();
    52 
    53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    54 
    55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    56 
    57     return x*f;
    58 
    59 }
    60 char s[10]="luvletter";
    61 int f[100];
    62 
    63 int main()
    64 
    65 {
    66 
    67     freopen("input.txt","r",stdin);
    68 
    69     freopen("output.txt","w",stdout);
    70 
    71     int cs=read();
    72     while(cs--)
    73     {
    74        char ch=' ';int now=0,ans=0;
    75        while((ch<='z'&&ch>='a')||(ch==' '))
    76        {
    77            ch=getchar();
    78            if(ch==s[now]){now++;if(now==9)now=0,ans++;}
    79        }
    80        printf("%d
    ",ans);
    81     }
    82 
    83     return 0;
    84 
    85 } 
    View Code
  • 相关阅读:
    SharedPreferences介绍,用来做数据存储
    android中的回调简单认识
    git的使用
    Android Studio插件美化Android Studio,文艺清新范
    arp欺骗技术
    进程和线程的关系
    Win下常用命令大全
    JavaWeb系列之:Servlet
    JavaWeb系列之:监听器
    JavaWeb系列之:过滤器
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/4111195.html
Copyright © 2020-2023  润新知