码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 66C Petya and File System

时间:2015-09-05 23:34:04      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

模拟题,map搞一搞。用了点c11的特性。

#include<bits/stdc++.h>
using namespace std;

typedef map<string,int> Node;
map<string,int>::iterator it_id;
const int maxnd = 1e4;
Node nds[maxnd];
int nds_cnt;
#define MP make_pair
#define fi first
#define se second

inline int id(const string& s,Node& fa)
{
    if((it_id = fa.find(s)) != fa.end()) return it_id->second;
    fa.insert(MP(s,++nds_cnt));
    return nds_cnt;
}

int curFile,curFolder;
void dfs(int u)
{
    for(auto it: nds[u]){
        if(nds[it.se].empty()) { curFile++; continue; }
        else curFolder++;
        dfs(it.se);
    }
}

#define cer(x) cout<<x<<endl;
#define PB push_back

int main()
{
    //freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    string s;
    while(cin>>s){
        auto u = nds;
        u = nds+id(s.substr(0,1),*u);
        s.PB(\\);
        for(int i = 3, j = 3; i < (int)s.size(); i++){
            if(s[i] == \\){
                u = nds+id(s.substr(j,i-j),*u);
                j = i+1;
            }
        }
    }
    int maxFolder = 0,maxFile = 0;

    for(auto it: nds[0]){
        for(auto it2: nds[it.se]){
            curFolder = curFile = 0;
            dfs(it2.se);
            maxFolder = max(maxFolder,curFolder);
            maxFile = max(maxFile,curFile);
        }
    }
    cout<<maxFolder<< <<maxFile<<endl;
    return 0;
}

 

CodeForces 66C Petya and File System

标签:

原文地址:http://www.cnblogs.com/jerryRey/p/4784178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!