zoukankan      html  css  js  c++  java
  • CCF 201809-3 元素选择器

    试题编号: 201809-3
    试题名称: 元素选择器
    时间限制: 1.0s
    内存限制: 256.0MB
    问题描述:



    //本代码采用非递归暴力循环匹配
    //注意题目 标签大小写不敏感,id大小写敏感
    #include<bits/stdc++.h>
    #define pb emplace_back
    using namespace std;
    const int N=1e5+5;
    struct node{
        string name,plus;int dj;
        node(){}
        node(string a,string b,int c):name(a),plus(b),dj(c){}
    }d[105];
    string s,at,t;int n,m,sz,cnt,res[N],ans[N];vector<string> v;
    inline void stdit(string &s){transform(s.begin(),s.end(),s.begin(),::tolower);}
    void readstable(){
        getline(cin,s);at="";
        int rk=0,pos=0;
        rk=s.find_first_not_of('.');
    //    s.erase(s.find_last_not_of(' ')+1);
        s=s.substr(rk);
        rk>>=1;
        pos=s.find('#');
        if(~pos){
            stringstream i(s);
            i>>s;
            i>>at;
        }
        stdit(s);
        d[++cnt]=node(s,at,++rk);
    }
    inline void ins(string s){if(s[0]!='#') stdit(s);v.pb(s);}
    void split(){
        v.clear();
        getline(cin,s);
    //    s.erase(s.find_last_not_of(' ')+1);
        int pos=s.find_first_of(' ');
        if(~pos){
            do{
                ins(s.substr(0,pos));
                s=s.substr(pos+1);
                pos=s.find_first_of(' ');
            }while(~pos);
        }
        ins(s);
    }
    void dfs(int cur,int cj,int lim=0){
        if(cur==sz){
            ans[++ans[0]]=res[sz-1];
            return ;
        }
        for(int j=lim+1;j<=n;j++){
            if(d[j].dj<=cj) return ;
            if(d[j].name==v[cur]||d[j].plus==v[cur]){
                res[cur]=j;
                dfs(cur+1,d[j].dj,j);
            }
        }
    }
    void query(){
        split();
        sz=v.size();
        int &cnt=ans[0];cnt=0;
        dfs(0,0,0);
        sort(ans+1,ans+cnt+1); 
        cnt=unique(ans+1,ans+cnt+1)-(ans+1);
        if(!cnt){puts("0");return ;}
        printf("%d ",cnt);
        for(int i=1;i<=cnt;i++) printf("%d ",ans[i]);
        puts("");
    }
    int main(){
        scanf("%d%d
    ",&n,&m);
        for(int i=0;i<n;i++) readstable();
        for(int i=0;i<m;i++) query();
        return 0;
    }
    /*
    11  5 
    html 
    ..head 
    ....title 
    ..body 
    ....h1 
    ....p #subtitle 
    ....div #main 
    ......h2 
    ......p #one 
    ......div 
    ........p #two 
    p 
    #subtitle 
    h3 
    div p 
    div div p 
    */
  • 相关阅读:
    第五课:数字门构造
    出一道题 : 证明 牛顿迭代法
    网友 水登江河 说
    出现 杨辉三角 的 一些 场合
    泰勒级数 无敌 逼近法
    出一道题 : 证明 ln | sec x + tan x | =
    从 角动量守恒 推导出 椭圆轨道
    三角函数 版 的 霍奇猜想
    傅里叶级数 和 高次多项式函数
    实际上, 物空必能 先生 的 一些 观点 可能 是 正确 的
  • 原文地址:https://www.cnblogs.com/shenben/p/12488771.html
Copyright © 2011-2022 走看看