• hdu 4329


    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329

    题意:模拟  a.           

                 p(r)=   R'/i   rel(r)=(1||0)  R是前n次输入有关URL的个数  R'是后n次已经输入有关URL的个数

                  b.

                

    另加:输入 istringstream

    #include<iostream>  
    #include<sstream>        //istringstream 必须包含这个头文件
    #include<string>  
    using namespace std;  
    int main()  
    {  
        string str="i an a boy";  
        istringstream is(str);  
        string s;  
        while(is>>s)  
        {  
            cout<<s<<endl;  
        }  
          
    } 

    #include<iostream>
    #include<sstream>
    #include<cstring>
    #include<cstdio>
    #include<map>
    #include<algorithm>
    using namespace std;
    char a[1005];
    int r[105];
    map<string,int>mp[105];
    void init(int k)
    {
        istringstream str(a);
        string tmp;
        str>>tmp;
        mp[k].clear();
        while(str>>tmp)
        {
            r[k]++;
            mp[k][tmp]=1;
        }
    }
    double get_avep(int k)
    {
        istringstream str(a);
        string tmp;
        str>>tmp;
        int i=0,R=0;
        double ansn=0.0;
        while(str>>tmp)
        {
            i++;
            if(mp[k][tmp]==1)
            {
                R++;
                ansn+=(R*1.0)/i;
            }
        }
        ansn/=r[k]*1.0;
        return ansn;
    }
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {   memset(r,0,sizeof(r));
            int n,kcas=0;
    
            cin>>n;
            getchar();
    
            for(int i=1;i<=n;++i)
            {
                  gets(a);
                 init(i);
             }
            double ans=0.0;
            for(int i=1;i<=n;++i)
            {
                gets(a);
    
                ans+=get_avep(i);
            }
            ans/=n;
            cout<<"Case #"<<++kcas<<": ";
            printf("%.6lf
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    「考试」省选62
    「考试」省选61
    「考试」省选59
    「刷题」THUPC泛做
    「考试」省选58
    「考试」省选57
    「考试」省选56
    「考试」省选55
    「考试」省选54
    「考试」省选52
  • 原文地址:https://www.cnblogs.com/sxy-798013203/p/5933879.html
Copyright © 2020-2023  润新知