zoukankan      html  css  js  c++  java
  • map的运用

    Advertising

    • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
    • Total Submission(s): 40     Accepted Submission(s): 6
    Description

    Maybe you have seen sports live, game live, etc. But you must have never seen GDCPC live before! Yes, the GDCPC committee decides to live stream the contest on their websites.

    You know, when there is a video, there is an ad. The website developers want to insert ads into the live stream. Since it's the first time to serve ads, the website developers just want to use the most standard way, VAST (Video Ad Serving Template).

    Basically, VAST is a XML and the video player plays ads inside it. An example looks like:

    <VAST version="2.0">

       <Ad id="1">

           <InLine>

               <Creative AdID="601364" />

           </InLine>

       </Ad>

       <Ad id="2">

           <Wrapper>

               <VASTAdTagURI>http://demo.ad.com/vast.xml</VASTAdTagURI>

           </Wrapper>

       </Ad>

    </VAST>

    Inside a VAST, there are two kinds of ads: inline ad and wrapper ad.

    For an inline ad, it contains one ID for interpret.

    For a wrapped ad, it contains an URL, which wrap another VAST.

    Video player interprets the VAST as following:

    1. Check the ads inside the VAST sequentially

    2. When encounter an inline ad, video player plays the media file inside it immediately, then move on to next ad.

    3. When encounter a wrapper ad, video player need to fetch the wrapped VAST by its URL. Then interprets the wrapped VAST recursively. After the interpretation is done, move on to next ad.

    Now the problem is to interpret the given VAST and output all inline ads IDs in order of appearance during interpretation.

    Input

    The first line is an integer T ( T ≤ 50 ), indicates the number of test cases.

    The first line of each test case contains one integer n indicates the number of VAST.

    For each VAST:

    1. First line contains an URL and an integer k, which indicates the number of ads in this VAST

    2. Then k lines follow, each line could be either "id inline" or "id wrapper URL"

    It's guaranteed that in each test case

    1. All VASTs have different URLs;

    2. Total number of ads (both inline and wrapper) among these VAST is less than 1000; the interpretation always succeeds.

    Output

    For each test case, output "Case #ts", t represents the index of test cases (start from 1), s represents the list of IDs when interpreting the first VAST, use space to separate the IDs.

    If there is no ID when interpreting, s should be empty.

    Sample Input

    2
    2
    http://demo.ad.com/vast1 2
    id1 wrapper http://demo.ad.com/vast2
    id2 inline
    http://demo.ad.com/vast2 1
    id3 inline
    4
    http://demo.ad.com/vast1 2
    id1 wrapper http://demo.ad.com/vast2
    id2 wrapper http://demo.ad.com/vast3
    http://demo.ad.com/vast2 1
    id3 wrapper http://demo.ad.com/vast4
    http://demo.ad.com/vast3 2
    id4 inline
    id5 inline
    http://demo.ad.com/vast4 1
    id6 inline

    Sample Output

    Case #1: id3 id2
    Case #2: id6 id4 id5

    Source
     
    题目大意:一个网页里面的广告,遇到wrapper表示跳转,inline表示已经访问到该广告。要求输出看到广告的先后顺序。
    这题主要是运用对map映射的应用。
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 map<string,vector<string> > mpa;
     5 map<string,bool> mpb;
     6 string root[1006];
     7 int n;
     8 bool flag;
     9 
    10 void dfs(string x)
    11 {
    12     if(mpb[x]){
    13         if(flag) cout<< " ";
    14         flag=1;
    15         cout << x ;
    16     }
    17     int len=mpa[x].size();
    18     for(int i=0;i<len;i++){
    19         dfs(mpa[x][i]);
    20     }
    21 }
    22 
    23 int main()
    24 {
    25     ios::sync_with_stdio(0); std::cin.tie(0);
    26     int T;
    27     cin >> T;
    28     for(int iii=1;iii<=T;iii++){
    29         mpa.clear();
    30         mpb.clear();
    31 
    32         cin >> n;
    33         string y,z,a;
    34         int m;
    35         for(int i=1;i<=n;i++){
    36             cin >> root[i] >> m;
    37             for(int j=1;j<=m;j++){
    38                 cin >> y >> z;
    39                 if(z[0]=='i'){
    40                     mpb[y]=true;
    41                     mpa[root[i]].push_back(y);
    42                 } else{
    43                     cin >> a;
    44                     mpa[root[i]].push_back(a);
    45                 }
    46             }
    47         }
    48         cout << "Case #" << iii << ": " ;
    49         flag=0;
    50         dfs(root[1]);
    51         cout << endl;
    52     }
    53     return 0;
    54 }
    View Code
     
  • 相关阅读:
    看了陈安之的文字 无论怎样 都要记住的是 你仍然是你自己 改变是应用他人的方法提高自己 改变是做更优秀更独特的自己
    流行的Ajax应用演示和源码下载(转)
    WEB2.0概念诠释(根据网络资料归纳)之一
    ASP.NET中文件上传下载方法集合(较为详细的介绍 转)
    建立梦想清单
    Ajax的应用
    Ajax的问题
    WEB2.0概念诠释(根据网络资料归纳)之三
    IIS突然挂掉
    VS2008软件90天过期,解决升级问题。
  • 原文地址:https://www.cnblogs.com/ZQUACM-875180305/p/9033051.html
Copyright © 2011-2022 走看看