栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2800 Any fool can do it

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2800 Any fool can do it

#include<iostream>#include<queue>#include<cstdio>#include<string.h>#include<cstdlib>using namespace std;enum {    SIZ = 208,};int len;char word[SIZ];char lst[SIZ][SIZ];char mat[SIZ][SIZ];bool isSet(int,int);bool isOne(int s, int e){    return s==e;}bool isNone(int s, int e){    return e<s;}bool atLeast2(int s, int e){    if(lst[s][e]!=-1) return lst[s][e];    int i;    for(i=s+1; i<e; i++){        if(word[i]!=',') continue;        if(!isOne(s,i-1) && !isSet(s,i-1)){ continue;        }        if(isOne(i+1,e)||isSet(i+1,e)||atLeast2(i+1,e)) return lst[s][e] = true;    }    return lst[s][e]=false;}bool isSet(int s,int e){    if(mat[s][e]!=-1)        return mat[s][e];    if(s>=e||word[s]!='{' || word[e]!='}')        return mat[s][e] = false;    return mat[s][e] = isNone(s+1,e-1)||isOne(s+1,e-1)  ||isSet(s+1,e-1)||atLeast2(s+1,e-1);}bool fun(){    len = strlen(word)-1;    memset(lst, -1, sizeof(lst));    memset(mat, -1, sizeof(mat));    return isSet(0, len);}int main(){    int tst, n=1;    scanf("%d", &tst);    while(tst--){        printf("Word #%d: ", n++);        scanf("%s", word);        if( !fun()){ printf("No ");        }        printf("Setn");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379543.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号