zoukankan      html  css  js  c++  java
  • 2017 Multi-University Training Contest

    2017 Multi-University Training Contest - Team 3

    1011 RXD's date

     

    Problem Description

     

    As we all know that RXD is a life winner, therefore he always goes out, dating with his female friends.
    Nevertheless, it is a pity that his female friends don't like extremely hot temperature. Due to this fact, they would not come out if it is higher than 35 degrees.
    RXD is omni-potent, so he could precisely predict the temperature in the next t days, but he is poor in counting.
    He wants to know, how many days are there in the next t days, in which he could go out and date with his female friends.
     
    Input
    There is only one test case.
    The first line consists of one integer t.
    The second line consists of t integers ci which means the temperature in the next t days.
    1t1000 
    0ci50
     
    Output
    Output an integer which means the answer.
     
    Sample Input
    5
    33 34 35 36 37

    Sample Output
    3
     
    题意:让你求出在n个数中有多少个数小于等于35
     
    题解:见过的多校最水的签到题之一,直接判断就可以了

     

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    int main()
    {
        int t,i,x;
        while (scanf("%d",&t) != EOF)
        {
            int ans = 0;
            for (i = 0;i < t;i++)
            {
                scanf("%d",&x);
                if (x <= 35) ans++;    
            }    
            printf("%d
    ",ans);
        }    
    } 

     

    1008 RXD and math

    Problem Description
    RXD is a good mathematician.
    One day he wants to calculate:

    output the answer module 109+7.
    ≤ n≤ 1018
    PS:
    μ(n) = 1 (n = 1)
    μ(n(1)(p1p2pk)
    μ(n) = 0 (otherwise)
    p1,p2,p3pk are different prime numbers.
     
    Input
    There are several test cases, please keep reading until EOF.
    There are exact 10000 cases.
    For each test case, there are 2 numbers n,k.
     
    Output
    For each test case, output "Case #x: y", which means the test case number and the answer.
     
    Sample Input
    10 10
     
    Sample Output
    Case #1: 999999937
     
    题意:给出μ(i)的定义为莫比乌斯函数,请计算这个式子。
     
    题解:通过打表可知,这个式子其实是有规律的,结果即为nk,因此直接裸快速幂即可解决。
     
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    long long n,k;
    const long long mod = 1e9 + 7;
    long long quick_power(long long a,long long b)  
    {  
        long long res = 1;  
        while (b > 0)  
        {  
            if (b & 1) res = (res * a) % mod;  
            a = (a * a) % mod;  
            b = b >> 1;  
        }  
        return res;  
    }  
    int main()
    {
        int count = 0;
        while (scanf("%lld%lld",&n,&k) != EOF)
        {
            count++;
            n = n % mod;
            printf("Case #%d: %lld
    ",count,quick_power(n,k));
        }
    }
     
     1005 RXD and dividing
    Problem Description
    RXD has a tree T, with the size of n. Each edge has a cost.
    Define f(S) as the the cost of the minimal Steiner Tree of the set S on tree T
    he wants to divide 2,3,4,5,6,n into k parts S1,S2,S3,Sk,
    where S{2,3,,n} and for all different i,j , we can conclude that S⋂ S
    Then he calulates ref({1⋃ Si).
    He wants to maximize the res.
    ≤ ≤ ≤ 106
    the cost of each edge ∈ [1,105]
    Si might be empty.
    f(S) means that you need to choose a couple of edges on the tree to make all the points in S connected, and you need to minimize the sum of the cost of these edges. f(S) is equal to the minimal cost.
     
    Input
    There are several test cases, please keep reading until EOF.
    For each test case, the first line consists of 2 integer n,k, which means the number of the tree nodes , and k means the number of parts.
    The next n1 lines consists of 2 integers, a,b,c, means a tree edge (a,b) with cost c.
    It is guaranteed that the edges would form a tree.
    There are 4 big test cases and 50 small test cases.
    small test case means n100.
     
    Output
    For each test case, output an integer, which means the answer.
     
    Sample Input
    5 4
    1 2 3
    2 3 4
    2 4 5
    2 5 6

    Sample Output
    27
     
    题意:给出一棵树,有n个点n - 1条边,设f(S)为树T的最小斯坦纳树的边权和。将2, 3, ..., n分成k个两两不相交的集合S1, S2, ..., Sk, 将1插入这些集合,求出这些集合的最小生成树,并使其权值和最大,求出这个值。
     
    补充:
           斯坦纳树:
           斯坦纳树问题是组合优化学科中的一个问题。将指定点集合中的所有点连通,且边权总和最小的生成树称为最小斯坦纳树(Minimal Steiner Tree),其实最小生成树是最小斯坦纳树的一种特殊情况。而斯坦纳树可以理解为使得指定集合中的点连通的树,但不一定最小。(最小生成树是在给定的点集和边中寻求最短网络使所有点连通。而最小斯坦纳树允许在给定点外增加额外的点,使生成的最短网络开销最小。)
     
    题解:以1为根建树,找出每条边下面有多少个点,若这条边下面的点数num > k, 则这条边需要被算k次;否则取num个点。这就相当于将这些点放到不同的集合中去,然后这些边可以多算几次。
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    #include<vector>
    using namespace std;
    int n,k;
    vector <int> map[1000050];
    vector <int> dist[1000050];
    int num[1000050];
    long long ans[1000050];
    void dfs(int x,int fa,int cost)
    {
        int i;
        num[x] = 1;
        for (i = 0;i < map[x].size();i++)
        {
            if (map[x][i] != fa)
            {
                dfs(map[x][i],x,dist[x][i]);
                ans[x] = ans[x] + ans[map[x][i]];
                num[x] = num[x] + num[map[x][i]]; 
            }
        }
        if (num[x] >= k) ans[x] = ans[x] + 1LL * k * cost;
        else ans[x] = ans[x] + 1LL * num[x] * cost;
    }
    int main()
    {
        int i,x,y,z;
        while (scanf("%d%d",&n,&k) != EOF)
        {
            for (i = 0;i <= n;i++) map[i].clear();
            for (i = 0;i <= n;i++) dist[i].clear();
            memset(num,0,sizeof(num));
            memset(ans,0,sizeof(ans));
            for (i = 1;i <= n - 1;i++)
            {
                scanf("%d%d%d",&x,&y,&z);
                map[x].push_back(y);
                dist[x].push_back(z);
                map[y].push_back(x);
                dist[y].push_back(z);
            }
            dfs(1,-1,0);
            printf("%lld
    ",ans[1]);
        }
    }
  • 相关阅读:
    c++之五谷杂粮4---explicit
    ping
    Swift常量和变量
    Swift数据类型简介
    Swift 注释
    Swift标示符以及关键字
    xcode简介
    认识Swift
    Android_adb详解
    详解Android AM命令
  • 原文地址:https://www.cnblogs.com/Suwako1997/p/7269152.html
Copyright © 2011-2022 走看看