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 
    */
  • 相关阅读:
    程序员面试中有几大法则
    css 页面重绘和回流(重排)以及优化
    (一)Windows下安装RabbitMQ服务
    NOT IN 和 OR 的SQL语句优化
    java更改图片格式,,更改图片大小,并实现多线程上传图片。
    数据库根据坐标查找附近的店铺
    Spring MVC接收提交文件图片的两种方式
    搜索引擎选择: Elasticsearch与Solr
    redis
    浅谈分布式事务
  • 原文地址:https://www.cnblogs.com/shenben/p/12488771.html
Copyright © 2011-2022 走看看