zoukankan      html  css  js  c++  java
  • 2019省赛训练组队赛3.26周二---FJUT 2016

    A.Minimum’s Revenge

    There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multiple of their indexes. 

    Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him? 

    InputThe first line contains only one integer T (T100T≤100), which indicates the number of test cases. 

    For each test case, the first line contains only one integer n (2n1092≤n≤109), indicating the number of vertices. 
    OutputFor each test case, output one line "Case #x:y",where x is the case number (starting from 1) and y is the total weight of the minimum spanning tree. 
    Sample Input

    2
    2
    3

    Sample Output

    Case #1: 2
    Case #2: 5

    代码:

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    int main()
    {
        int T,tot=0;
        cin>>T;
        while(T--)
        {
            ll n;
            scanf("%lld",&n);
            ll ans=(n+1)*n/2;
            ans--;
            printf("Case #%d: %lld
    ",++tot,ans);
        }
    
    
    
        return 0;
    }
    View Code

    C.Mr. Frog’s Problem

    One day, you, a clever boy, feel bored in your math class, and then fall asleep without your control. In your dream, you meet Mr. Frog, an elder man. He has a problem for you. 

    He gives you two positive integers A and B, and your task is to find all pairs of integers (C, D), such that ACB,ADBA≤C≤B,A≤D≤B and AB+BACD+DCAB+BA≤CD+DC

    Inputfirst line contains only one integer T (T125T≤125), which indicates the number of test cases. Each test case contains two integers A and B (1AB10181≤A≤B≤1018).OutputFor each test case, first output one line "Case #x:", where x is the case number (starting from 1). 

    Then in a new line, print an integer s indicating the number of pairs you find. 

    In each of the following s lines, print a pair of integers C and D. pairs should be sorted by C, and then by D in ascending order. 
    Sample Input

    2
    10 10
    9 27

    Sample Output

    Case #1:
    1
    10 10
    Case #2:
    2
    9 27
    27 9

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int T;
    long long A, B, C, D;
    
    int main() {
        scanf("%d", &T);
        for(int t = 1; t <= T; t ++) {
            scanf("%lld%lld", &A, &B);
            printf("Case #%d:
    ", t);
            if(A == B) {
                printf("1
    ");
                printf("%lld %lld
    ", A, B);
            } else {
                printf("2
    ");
                printf("%lld %lld
    ", A, B);
                printf("%lld %lld
    ", B ,A);
            }
        }//
        return 0;
    }
    View Code

    E.Mr. Frog’s Game

    One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese). 



    In this game, if you can draw at most three horizontal or vertical head-and-tail-connected lines over the empty grids(the lines can be out of the whole board) to connect two non-empty grids with the same symbol or the two non-empty grids with the same symbol are adjacent, then you can change these two grids into empty and get several more seconds to continue the game. 

    Now, Mr. Frog starts a new game (that means there is no empty grid in the board). If there are no pair of grids that can be removed together,Mr. Frog will say ”I’m angry” and criticize you. 

    Mr. Frog is battle-scarred and has seen many things, so he can check the board in a very short time, maybe one second. As a Hong Kong Journalist, what you should do is to check the board more quickly than him, and then you can get out of the room before Mr. Frog being angry. 

    InputThe first line contains only one integer T (T500T≤500), which indicates the number of test cases. 

    For each test case, the first line contains two integers n and m (1n,m301≤n,m≤30). 

    In the next n lines, each line contains m integers,  j-th number in the i-th line means the symbol on the grid(the same number means the same symbol on the grid). 
    OutputFor each test case, there should be one line in the output. 

    You should output “Case #x: y”,where x is the case number(starting from 1), and y is a string representing the answer of the question. If there are at least one pair of grids that can be removed together, the y is “Yes”(without quote), else y is “No”.Sample Input

    2
    3 3
    1 2 1
    2 1 2
    1 2 1
    3 3
    1 2 3
    2 1 2
    3 2 1

    Sample Output

    Case #1: Yes
    Case #2: No
    

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    int a[35][35];
    map <int,int> Map;
    int main()
    {
        int T,tot=0;
        cin>>T;
        while(T--)
        {
            Map.clear();
            int n,m;
            scanf("%d%d",&n,&m);
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    scanf("%d",&a[i][j]);
                }
            }
    
            int flag=0;
            for(int i=1;i<=m;i++)
            {
                if(!Map[a[1][i]]) Map[a[1][i]]=1;
                else flag++;
            }
            if(flag)
            {
                printf("Case #%d: Yes
    ",++tot);
                continue;
            }
            Map.clear();
            for(int i=1;i<=m;i++)
            {
                if(!Map[a[n][i]]) Map[a[n][i]]=1;
                else flag++;
            }
            if(flag)
            {
                printf("Case #%d: Yes
    ",++tot);
                continue;
            }
            Map.clear();
            for(int i=1;i<=n;i++)
            {
                if(!Map[a[i][1]]) Map[a[i][1]]=1;
                else flag++;
            }
            if(flag)
            {
                printf("Case #%d: Yes
    ",++tot);
                continue;
            }
            Map.clear();
            for(int i=1;i<=n;i++)
            {
                if(!Map[a[i][m]]) Map[a[i][m]]=1;
                else flag++;
            }
            if(flag)
            {
                printf("Case #%d: Yes
    ",++tot);
                continue;
            }
    
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m-1;j++)
                {
                    if(a[i][j]==a[i][j+1])
                    {
                        flag++;
                    }
                }
                if(flag) break;
            }
            if(flag)
            {
                printf("Case #%d: Yes
    ",++tot);
                continue;
            }
    
            for(int i=1;i<=m;i++)
            {
                for(int j=1;j<=n-1;j++)
                {
                    if(a[j][i]==a[j+1][i])
                    {
                        flag++;
                    }
                }
                if(flag) break;
            }
            if(flag)
            {
                printf("Case #%d: Yes
    ",++tot);
                continue;
            }
            else
            {
                printf("Case #%d: No
    ",++tot);
            }
        }
    
    
        return 0;
    }
    View Code

    F.Auxiliary Set

    Given a rooted tree with n vertices, some of the vertices are important. 

    An auxiliary set is a set containing vertices satisfying at least one of the two conditions: 

    ∙It is an important vertex 
    ∙It is the least common ancestor of two different important vertices. 

    You are given a tree with n vertices (1 is the root) and q queries. 

    Each query is a set of nodes which indicates the unimportant vertices in the tree. Answer the size (i.e. number of vertices) of the auxiliary set for each query. 

    InputThe first line contains only one integer T (T1000T≤1000), which indicates the number of test cases. 

    For each test case, the first line contains two integers n (1n1000001≤n≤100000), q (0q1000000≤q≤100000). 

    In the following n -1 lines, the i-th line contains two integers ui,vi(1ui,vin)ui,vi(1≤ui,vi≤n)indicating there is an edge between uiuii and vivi in the tree. 

    In the next q lines, the i-th line first comes with an integer mi(1mi100000)mi(1≤mi≤100000)indicating the number of vertices in the query set.Then comes with mi different integers, indicating the nodes in the query set. 

    It is guaranteed that qi=1mi100000∑i=1qmi≤100000. 

    It is also guaranteed that the number of test cases in which n1000n≥1000  or qi=1mi1000∑i=1qmi≥1000 is no more than 10. 
    OutputFor each test case, first output one line "Case #x:", where x is the case number (starting from 1). 

    Then q lines follow, i-th line contains an integer indicating the size of the auxiliary set for each query. 
    Sample Input

    1
    6 3
    6 4
    2 5
    5 4
    1 5
    5 3
    3 1 2 3
    1 5
    3 3 1 4

    Sample Output

    Case #1:
    3
    6
    3
    

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5 + 10;
    int T;
    int a[maxn];
    int deep[maxn], fa[maxn], son[maxn], soon[maxn];
    vector<int> v[maxn];
    
    void dfs(int child, int parent) {
        fa[child] = parent;
        deep[child] = deep[parent] + 1;
        son[child] = 0;
        
        for(int i = 0; i < v[child].size(); i ++) {
            if(v[child][i] != parent) {
                dfs(v[child][i], child);
                son[child] ++;
            }
        }
    
    }
    
    bool cmp(int a, int b) {
        return deep[a] > deep[b];
    }
    
    int main() {
        scanf("%d", &T);
        for(int t = 1; t <= T; t ++) {
            int N, M;
            scanf("%d%d", &N, &M);
            
            for(int i = 1; i <= N; i ++)
                v[i].clear();
                
            for(int i = 0; i < N - 1; i ++) {
                int st, en;
                scanf("%d%d", &st, &en);
                v[st].push_back(en);
                v[en].push_back(st);
            }
    
            printf("Case #%d:
    ", t);
            dfs(1, 0);
            while(M --) {
                int K;
                scanf("%d", &K);
                int ans = N - K;
                for(int i = 0; i < K; i ++) {
                    scanf("%d", &a[i]);
                }
    
                sort(a, a + K, cmp);
    
                for(int i = 0; i < K; i ++)
                    soon[a[i]] = son[a[i]];
    
                for(int i = 0; i < K; i ++) {
                    if(soon[a[i]] >= 2) ans ++;
                    else if(soon[a[i]] == 0)
                        soon[fa[a[i]]] --;
                }
    
                printf("%d
    ", ans);
    
            }
    
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Android获取SIM卡信息--TelephonyManager
    android2.2应用开发之IccCard(sim卡或USIM卡)
    简易计算器
    c++ 按行读取txt文本
    poj 2010 Moo University
    字符串的最长公共子序列问题
    常用工具之zabbix
    常用工具之stunnel
    oracle 查看表属主和表空间sql
    linux shell执行方式
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10603025.html
Copyright © 2011-2022 走看看