zoukankan      html  css  js  c++  java
  • gym101350 c h m

    C. Cheap Kangaroo
    time limit per test
    1.0 s
    memory limit per test
    256 MB
    input
    standard input
    output
    standard output

    There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants to eat exactly xi food. The kangaroos all want to order the same size of plates, but each one can order more than one plate for themselves if they need to. If the kangaroo orders more than he needs, he can simply hide the leftovers in his pouch.

    At this Indian restaurant, the cost of the plate is the same as its size. Since Karl the Kangaroo is paying and is low on money, he wants to know what is the minimum cost to feed all N kangaroos and what is the largest possible size of the plates that satisfies this minimum cost?

    Input

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

    The first line of each test case is an integer N (1 ≤ N ≤ 105).

    The second line contains N space-separated integers xi (1 ≤ xi ≤ 109).

    Output

    For each test case, output a line containing two space-separated integers – the minimum cost and the maximum plate size that corresponds to when the total cost is minimized.

    Example
    input
    2
    1
    5
    2
    4 2
    output
    5 5
    6 2

     思路:题意不说了,应该都看得懂,这题乍一看感觉很难,但其实最低价就是每个人都用容量为1的盘子,这样是不会产生浪费的,而满足最低价的最大盘子,肯定是所有数的最大公约数了.

    实现代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    int gcd(int a,int b)
    {
         return b?gcd(b,a%b):a;
    }
    int main()
    {
        ll t,n,x,y;
        scanf("%lld",&t);
        while(t--){
            scanf("%lld",&n);
            scanf("%lld",&x);
            if(n==1){
                printf("%lld %lld
    ",x,x);
            }
            else{
                ll sum = x;
                ll ans = x;
                for(int i = 1; i < n;i ++){
                    scanf("%lld",&y);
                    sum += y;
                    ans = gcd(ans,y);
                }
                printf("%lld %lld
    ",sum,ans);
            }
        }
    }
     
    H. Mirrored String I
    time limit per test
    1.0 s
    memory limit per test
    256 MB
    input
    standard input
    output
    standard output

    The gorillas have recently discovered that the image on the surface of the water is actually a reflection of themselves. So, the next thing for them to discover is mirrored strings.

    A mirrored string is a palindrome string that will not change if you view it on a mirror.

    Examples of mirrored strings are "MOM", "IOI" or "HUH". Therefore, mirrored strings must contain only mirrored letters {A, H, I, M, O, T, U, V, W, X, Y} and be a palindrome.

    e.g. IWWI, MHHM are mirrored strings, while IWIW, TFC are not.

    A palindrome is a string that is read the same forwards and backwards.

    Can you tell if string S is a mirrored string?

    Input

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

    Each test case contains a non-empty string S of maximum length 1000. The string contains only uppercase English letters.

    Output

    For each test case, output "yes" (without quotes) if the string S is a mirrored string, otherwise output "no".

    Example
    input
    3
    IOI
    ARABELLA
    RACECAR
    output
    yes
    no
    no

     思路:

    水题

    实现代码:

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        char  s[2000];
        char a[15] = "AHIMOTUVWXY";
        int n;
        cin>>n;
        while(n--){
        scanf("%s",s);
        int len = strlen(s);
        int flag,flag1 = 0;
        for(int i = 0 ;i < len;i++){
            flag = 0;
            for(int j = 0;j < 11;j++){
                if(s[i]==a[j]){
                    flag  = 1;
                    break;
                }
            }
            if(flag == 0){
                cout<<"no"<<endl;
                flag1 = 1;
                break;
            }
        }
        if(flag1) continue;
        for(int i = 0;i < len/2;i++){
            if(s[i]!=s[len-i-1]){
                cout<<"no"<<endl;
                flag1 = 1;
                break;
            }
        }
        if(flag1) continue;
        else
        cout<<"yes"<<endl;
        }
        return 0;
    }
    M. Make Cents?
    time limit per test
    6.0 s
    memory limit per test
    256 MB
    input
    standard input
    output
    standard output

    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 Viof 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

     思路:

    水题

    实现代码:

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t,n,m;
        double x;
        char s[200000];
        scanf("%d",&t);
        while(t--){
            double ans = 0.0;
            map<string,double>mp;
            scanf("%d%d",&n,&m);
            mp["JD"] = 1;
            for(int i = 1;i <= n;i ++){
                scanf("%s",s);
                string s1 = s;
                scanf("%lf",&x);
                mp[s1] = x;
            }
            for(int i = 1;i <= m;i ++){
                scanf("%lf",&x);
                scanf("%s",s);
                string s1 = s;
                ans += x*mp[s1];
            }
            printf("%.6lf
    ",ans);
            mp.clear();
        }
    }
  • 相关阅读:
    【GIS】SuperMap加载三维服务
    【GIS】SuperMap-Web3D-Sql查询示例
    【GIS】Cesium绘制轨迹线
    【GIS】Cesium地下模式设置
    【Java】jfinal-layui:org.postgresql.util.PSQLException: ERROR: syntax error at or near "value" 位置:11
    【Java】jfinal-layui、postgres
    【JavaScript】js注入
    【可视化】地质油藏可视化之四-面元渐进涂色
    【可视化】地质油藏可视化之三-基于threejs绘制三维zmap数据
    【可视化】地质油藏可视化之一-zmap数据转换
  • 原文地址:https://www.cnblogs.com/kls123/p/8067830.html
Copyright © 2011-2022 走看看