zoukankan      html  css  js  c++  java
  • stl应用(map)或字典树(有点东西)

    M - Violet Snow

    Gym - 101350M

    Every year, an elephant qualifies to the Arab Collegiate Programming Competition. He graduated this year, but that’s irrelephant. What’s important is that the location of the competition might not have been the same every year. Therefore, after every trip, he always has leftover money in the currency of the country he visited.

    Now he wants to see how much Jordanian Dinars he has after all those competitions. Can you help him convert the leftover money from all competitions to Jordanian Dinar, if that makes any cents?


    Input

    The first line of input is T – the number of test cases.

    The first line of each test case contains C and N (1 ≤ C, N ≤ 100000), the number of currency types and the number of competitions, respectively.

    The next C lines each contain the name of the currency Ci of maximum length 10 in lowercase and/or uppercase letters, and the value Vi of that currency in Jordanian Dinar (0 < Vi ≤ 1000). The names are case-sensitive.

    The next N lines each contains an amount left over from each competition (0 ≤ Ni ≤ 1000), and the name of the currency of that amount (it is guaranteed that the name was either given in the input or is “JD”).

    Output

    For each test case, print on a single line the total amount of money he has in Jordanian Dinar(JD) rounded to 6 decimal digits.

    Example
    Input
    1
    3 5
    dollar 0.71
    euro 0.76
    turkish 0.17
    5.1 dollar
    6 dollar
    7 turkish
    3 euro
    1.1 JD
    Output
    12.451000
    https://blog.csdn.net/sevenjoin/article/details/81943864

    自动建立key - value的对应。key 和 value可以是任意你需要的类型。
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <algorithm>
    #include <iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include <stdio.h>
    #include <string.h>
    #include <map>
    //#define PI 3.1415926
    using namespace std;
    const double PI = acos(-1.0);
    
    
    int main()
    {
        int n ;
        scanf("%d" , &n);
        while(n--)
        {
            map<string , double>ma;
            int m , p ;
            scanf("%d%d" , &m ,&p);
            for(int i = 0 ; i < m ; i++)
            {
                string a ;
                double b ;
                cin >> a ;
                scanf("%lf" , &b);
                //map容器的三种插入,第一种key可以覆盖 ,其他两种不可以
                ma[a] = b;
                ma.insert(map<string , double>::value_type(a , b));
                ma.insert(pair<string , double>(a , b));
            }
            double sum = 0 ;
            for(int i = 0 ; i < p ; i++)
            {
                string a ;
                double b;
                scanf("%lf" , &b);
                cin >> a;
                if(a == "JD")
                    sum += b ;
                else
                    sum += ma[a] * b ;
            }
            printf("%.6lf
    " , sum);
        }
    
        return 0 ;
    }

    应该没几个人用字典树吧

    字典树是完全可行的,我就是因为没对用过的树初始化所有就wa了,

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <algorithm>
    #include <iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include <stdio.h>
    #include <string.h>
    using namespace std;
    int tree[500009][65];
    int k = 0 ;
    double vis[500009] ;
    double sum = 0 ;
    void winsert(char *a , double val)
    {
        int len = strlen(a);
        int p = 0 ;
        for(int i = 0 ; i < len ; i++)
        {
            int c = a[i] - 'A';
            if(!tree[p][c])
                tree[p][c] = ++k ;
            p = tree[p][c];
        }
        vis[p] = val ;
    }
    
    double wsearch(char *a)
    {
        int p = 0 ;
        int len = strlen(a);
        for(int i = 0 ; i < len ; i++)
        {
            int c = a[i] - 'A';
            if(!tree[p][c]) return 1 ;
            p = tree[p][c];
        }
        if(vis[p])
            return vis[p];
    }
    
    
    int main()
    {
        int n ;
        scanf("%d" , &n);
        while(n--)
        {
            k = 0 ;
            memset(vis, 0 , sizeof(vis));
            memset(tree , 0 , sizeof(tree));
            sum = 0 ;
            int m , p ;
            scanf("%d%d" , &m ,&p);
           // cout << m << " " << p << endl ;
            char s[100];
            double val ;
            for(int i = 0 ; i < m ; i++)
            {
                scanf("%s%lf" ,s , &val);
                winsert(s , val);
            }
            for(int i = 0 ; i < p ; i++)
            {
                scanf("%lf%s" , &val , s);
                sum += val * wsearch(s);
            }
            printf("%.6lf
    " , sum);
    
        }
    
    
    
        return 0 ;
    }
  • 相关阅读:
    python中的map,reduce,filter函数和lambda表达式
    GAN相关:SRGAN,GAN在超分辨率中的应用
    GAN相关:PAN(Perceptual Adversarial Network)/ 感知对抗网络
    GAN相关 : pix2pix模型
    GAN相关(二):DCGAN / 深度卷积对抗生成网络
    NCRE-3 网络技术概念图:局域网技术
    NCRE-3 网络技术概念图:路由设计基础
    NCRE-3 网络技术概念图:IP地址规划设计技术
    NCRE-3 网络技术概念图:中小型网络系统总体规划与设计方法
    NCRE-3 网络技术概念图:网络系统结构与设计基本原则
  • 原文地址:https://www.cnblogs.com/nonames/p/11290922.html
Copyright © 2011-2022 走看看