zoukankan      html  css  js  c++  java
  • 15.4.19 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛

    Problem 1564 - A - Circle
    Time Limit: 4000MS   Memory Limit: 65536KB   
    Total Submit: 349  Accepted: 73  Special Judge: No
    Description
    Here is a circle sequence S of length n, and you can choose a position and remove the number on it.
    After that,you will get a integer. More formally,you choose a number x( 1<=x<=n ),then you will get the integer Rx = Sx+1……SnS1S2…..Sx-1.
    The problem is which number x you choose will get the k-th smallest Rx.
    If there are more than one answer,choose the one with the smallest x.
    Input
    First line of each case contains two numbers n and k.(2 ≤ k≤  n ≤ 1 000 000).

    Next line contains a number of length n. Each position corresponds to a number of 1-9.
    Output
    Output x on a single line for each case.
    Sample Input
    10 5
    6228814462
    10 4
    9282777691
    Sample Output
    6
    7
    Hint
     
    Source
     
    不会做,网上神牛代码膜拜一发
    Problem 1565 - B - Magic
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 445  Accepted: 168  Special Judge: No
    Description
    Here are n numbers.
    You have a magic first , you choose a interval [l,r],and then each Si(l<=i<=r) will be ( 10 – Si ) % 10.
    You can use the magic at most once to make sum of all the numbers to be maximum.
    What is the maximum sum you can get?
    Input
    First line of each case contains a number n.(1 ≤  n ≤ 1 000 000).

    Next line contains n numbers without space-separated. Each position corresponds to a number of 0-9.
    Output
    Output the answer on a single line for each case.
    Sample Input
    10
    3775053808
    10
    2580294019
    10
    4701956095
    Sample Output
    50
    50
    54
    Hint
     
    Source
     
    题意:
    给定一串数字序列,选定一个区间[l,r],把区间里面的元素转变成(10-xi)%10,且最多转换一次,问数字序列的最大的和是多少?
    分析:
    把对应的转变的xi'和原来的xi相减就得到转变之后和转变之前两个对应的数字相差多少。
    然后可以转变成求最大连续子序列和,得出的值与原序列的和相加。
    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<queue>
    #include<stack>
    #include<vector>
    #include<stdlib.h>
    #include<algorithm>
    using namespace std;
    const int MAXN=1000000+5;
    const int INF=0x3f3f3f3f;
    char str[MAXN];
    int a[MAXN],b[MAXN],c[MAXN],dp[MAXN];
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            memset(dp,0,sizeof(dp));
    
            scanf("%s",str+1);
            int len=strlen(str+1),sum=0;
            for(int i=1;i<=len;i++)//将数组转变做差得到相差的数字序列
            {
                a[i]=str[i]-'0';
                b[i]=(10-a[i])%10;
                c[i]=b[i]-a[i];
                sum+=a[i];
            }
    
            int maxn=-INF;
            for(int i=1;i<=n;i++)//求最大连续子序列
            {
                if(dp[i-1]+c[i]<c[i]) dp[i]=c[i];
                else dp[i]=dp[i-1]+c[i];
                if(dp[i]>maxn) maxn=dp[i];
            }
            printf("%d
    ",sum+maxn);
        }
        return 0;
    }
    View Code
     
     
    Problem 1566 - C - Spanning Tree
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 383  Accepted: 82  Special Judge: No
    Description
    You are given a graph with N nodes and M edges. 
    Then every time you are required to add an additional edge with weight Wi connecting the node Ai and Bi in the graph, and then calculate the sum of the edges’ weight of the Minimum Spanning Tree of the current graph. You’ll be asked to complete the mission for Q times.
    The Minimum Spanning Tree of a graph is defined to be a set of N - 1 edges which connects all the N nodes of the graph and the sum of all the edges is as small as possible.
    It's guaranteed that the graph is connected.
    Input
    First line of each case contains three numbers N , M and Q.(1 ≤  N,Q ≤ 1000, 1 ≤  M ≤ 100000 ,)

    The following M lines contains three numbers Ai , Bi and Wi.( 1 ≤  Ai, Bi ≤ 1000, 1 ≤  Wi≤ 100000).

    The last Q lines of this case contains three numbers Ai , Bi and Wi. ( 1 <= Ai, Bi <= 1000, 1 ≤  Wi≤ 100000 ). 
    Output
    Output the answer in a single line for each case.
    Sample Input
    3 3 3
    2 1 8
    3 1 4
    1 2 6
    1 2 4
    2 3 1
    1 1 4
    3 3 3
    2 1 7
    3 2 8
    3 3 6
    1 3 3
    2 2 3
    2 2 3
    Sample Output
    8
    5
    5
    10
    10
    10
    Hint
     
    Source
     
    题意:
    给定N个点和M条边,然后每次添加一条边求最小生成树
    分析:
    先求一次最小生成树,记录下边,则最后生成最小生成树的时候会有n-1条边,每次添加一条新边求最小生成树
    那么,如果这条边存在的话,权值比原来的记录的边的权值大的话,就不更新。如果权值比原来的记录的边的权值小的话,就更新最小值并记录。
    如果这条边不存在的话,就会删掉一条边,生成新的最下生成树。
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stdlib.h>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<ctype.h>
    #define LL __int64
    using namespace std;
    const int MAXN=100000+5;
    const int MAX=1000+5;
    struct node
    {
        int s;
        int e;
        int val;
        bool operator<(const node A) const
        {
            return val < A.val;
        }
    }
    a[MAXN],b[MAX];
    int p[MAX],ans,cnt;
    int n,m,q;
    
    int findfa(int x)
    {
        p[x]==x?x:p[x]=findfa(p[x]);
    }
    
    int kru()
    {
        int res = 0;
        sort(a,a+m);
        for (int i=1;i<=n;i++)
            p[i]=i;
    
        for (int i=0;i<m;i++)
        {
            int x=findfa(a[i].s);
            int y=findfa(a[i].e);
            if (x!=y)
            {
                p[x]=y;
                b[cnt++]=a[i];
                res+=a[i].val;
            }
        }
        return res;
    }
    
    int kru1(node now)
    {
        int res=0;
        cnt=0;
        b[n-1]=now;
        sort(b,b+n);
        for (int i=1;i<=n;i++)
            p[i]=i;
    
        for (int i=0;i<n;i++)
        {
            int x=findfa(b[i].s);
            int y=findfa(b[i].e);
            if (x!=y)
            {
                p[x]=y;
                b[cnt++]=b[i];
                res+=b[i].val;
            }
        }
        return res;
    }
    
    int main()
    {
        while (scanf("%d %d %d",&n,&m,&q)!=EOF)
        {
            for (int i=0;i<m;i++)
                scanf("%d %d %d",&a[i].s,&a[i].e,&a[i].val);
            cnt=0;
            kru();
            while(q--)
            {
                node now;
                scanf("%d %d %d",&now.s,&now.e,&now.val);
                ans=kru1(now);
                printf("%d
    ",ans);
            }
        }
        return 0;
    }
    View Code
    Problem 1567 - D - Sloth's Angry
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 347  Accepted: 118  Special Judge: No
    Description
    A forest is full of sloths, they are so eager for tree leaves and as a result, very angry.
    We assume that the forest is a map of N * M grids, and each of the gird is an empty land or contains a big sloth. It’s guaranteed that the sequence of the sloth is a continuous segment from the leftmost column for every row. ( You may consider that the number of columns M is infinite ).
    As a sloth lover, you want to feed all the sloths as quick as possible. Every second you may select a rectangle area of the grids which only contains sloths and feed all the sloths there.
    What’s the minimum time required to meet all the sloths’ needs in the forest?
    Input
    First line of each case contains one numbers N.(1≤  n ≤ 1 000).

    The following line contains N numbers Ai, each describing the length of continuous sloths sequence from the left most column in every row. ( 1 <= Ai <= 10^9 )
    Output
    Output the answer on a single line for each case.
    Sample Input
    4
    3 4 5 5
    Sample Output
    3
    Hint

    The distributing situation of the sloths in the sample is as follow:

    SSS

    SSSS

    SSSSS

    SSSSS

    And you can choose three rectangles to cover it.

    Source
     
    题意:S代表树懒,求用最少的矩形,把树懒围起来,矩形里面只能有树懒不能有空地。
    分析:贪心的一种算法吧,题目给了每行树懒的个数,可以看成有n条线段,每条线段的长度都知道,然后可以每次截取连续的线段里面的最短长度,直至所有线段长度都截止为0
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stdlib.h>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<ctype.h>
    #define LL __int64
    using namespace std;
    const int MAXN=1000+5;
    const int INF=0x3f3f3f3f;
    int a[MAXN],id,n;
    bool judge(int a[])
    {
        int Minn=INF;
        for(int i=0;i<n;i++)
            if(a[i]!=0 && a[i]<Minn)
            {
                Minn=a[i];
                id=i;
            }
        if(Minn==INF) return false;
        else return true;
    }
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            int minn=INF;
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
                if(a[i]<minn) minn=a[i];
            }
            int cnt=1;
            for(int i=0;i<n;i++) a[i]=a[i]-minn;
    
            while(judge(a))
            {
                int minnum=a[id];
                for(int i=id;i>=0;i--)
                {
                    if(a[i]==0) break;
                    a[i]=a[i]-minnum;
                }
                for(int i=id+1;i<n;i++)
                {
                    if(a[i]==0) break;
                    a[i]=a[i]-minnum;
                }
                cnt++;
            }
            printf("%d
    ",cnt);
        }
        return 0;
    }
    View Code
    Problem 1568 - E - Product
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 225  Accepted: 41  Special Judge: No
    Description
    The function f(x) is defined as the product of each numerical digit of the number x.
    You are given a number n and required to calculate the number of x that satisfies f(x) = f(n) and doesn’t have number 1 as its numerical digit. 
    Input
    First line of each case contains a number len. ( 1 <= len <= 50 )

    Next line contains a number n of length len..Each position corresponds to a number of 1-9.
    No more than 10000 cases.
    Output
    Output the answer modulo 1 000 000 007 in a single line for each case.
    Sample Input
    2
    72
    3
    568
    4
    4123
    Sample Output
    2
    176
    17
    Hint
     
    Source
     
    活捉野生JKL大神一只~ORZ
     
    Problem 1569 - F - Subtract
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 325  Accepted: 133  Special Judge: No
    Description
    The number A is connected by n numerical digit a1a2a3a4……an.
    You can separate it into two parts as a1a2a3..ak and ak+1ak+2…an and subtract the smaller one from the bigger one to get the number B.
    Please find the minimum result of number B.
    Input
    First line of each case contains a number A.( 10 <= A <= 10^20 )
    Output
    Output the answer in a single line for each case.
    Sample Input
    457
    75462
    734794666
    Sample Output
    38
    387
    68813
    Hint
     
    Source
     
    题意:给一个字符串数字,问怎么将数字分成两个数字,使得两个数字的差的绝对值最小?
    分析:水题,直接从中间截取便是最小的,长度为奇数的时候有两种情况,取两种情况的最小值。
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stdlib.h>
    #include<algorithm>
    #include<queue>
    #include<vector>
    #include<ctype.h>
    #define LL __int64
    using namespace std;
    const int MAXN=30;
    char str[MAXN];
    
    int work(char str[])
    {
        int len=strlen(str);
        int num1=0,num2=0,ans1,ans2;
        if(len%2==1)
        {
            for(int i=0;i<=len/2;i++) num1=num1*10+(str[i]-'0');
            for(int i=len/2+1;i<len;i++) num2=num2*10+(str[i]-'0');
            ans1=abs(num1-num2);
    
            num1=0,num2=0;
            for(int i=0;i<len/2;i++) num1=num1*10+(str[i]-'0');
            for(int i=len/2;i<len;i++) num2=num2*10+(str[i]-'0');
            ans2=abs(num1-num2);
    
            return min(ans1,ans2);
        }
        else
        {
            for(int i=0;i<len/2;i++)
                num1=num1*10+(str[i]-'0');
            for(int i=len/2;i<len;i++)
                num2=num2*10+(str[i]-'0');
            return abs(num2-num1);
        }
    
    }
    
    int main()
    {
        while(scanf("%s",str)!=EOF)
        {
            int ans;
            ans=work(str);
            printf("%d
    ",ans);
        }
        return 0;
    }
    View Code
    Problem 1570 - G - April disease
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 243  Accepted: 128  Special Judge: No
    Description
    Holding a contest is an interesting mission, and apparently arranging the problems is not exceptional, either.
    You may consider that there are N problems prepared, and it's required to choose M problems to form the problem set of the upcoming contest.
    What's more, the evaluating function of all the problems choosed is as follows:
    Where Xi represents the hardness of the i_th problem and X represents the average of the M problems.
    However, the contest principal Alice has lost himself in April disease, and just wants to hold the worst contest ever.(Sounds horrible...)
    Now he wonders, what's the minimum value of s^2 can be.
    Input
    The first line of each test case contains two numbers N and M. ( 1 <= M <= N <= 30 )

    The following line will contain N numbers Xi. ( 1 <= Xi <= 10^9 )
    Output
    For each test case, output your answer in one line.
    (Please keep three decimal places.)
    Sample Input
    4 3
    6 10 1 2
    5 2
    1 8 3 4 9
    Sample Output
    4.667
    0.250
    Hint
     
    Source
     
    题意:N个数选其中M个求最小方差。
    分析:既然是方差最小,那么数字肯定是越连续方差越小,所以先把数字排序,然后每次取M个数,计算方差更新最小值。
    队友敲的= =
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<queue>
    #include<algorithm>
    using namespace std;
    const int INF=0x3f3f3f3f;
    int a[35],n,m;
    int main()
    {
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            double sum,ave,ans,cnt=INF,t=0;
            for(int i=0; i<n; i++)
                scanf("%d",&a[i]);
            sort(a,a+n);
            for(int j=0; j<n-1; j++)
            {
                sum=0;ans=0;
                for(int i=t; i-t<m; i++)
                    sum+=a[i];
                ave=sum/m;
                for(int i=t; i-t<m; i++)
                {
                    ans+=(a[i]-ave)*(a[i]-ave);
                }
                ans/=m;
                if(cnt>ans)cnt=ans;
                t++;
            }
            printf("%.3lf
    ",cnt);
    
        }return 0;
    }
    View Code
    Problem 1571 - H - Things after school
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 285  Accepted: 119  Special Judge: No
    Description

    Alice, Fzz’s daughter is a primary school student. Fzz loves his daughter so much that he drives to school every day exactly on time when the school day is over, which means when Fzz arrives school the school day is exactly over.

    It is the 100th anniversary celebration of school today. After some interesting activities, the principal announce that school is over. Alice watches her watch, and she knows it is x minutes earlier compared to the time when the school day usually ends. She starts to go home.

    After y minutes, she meets her Dad. Then she gets on the car. They go home happily by car.

    When she arrives home, she finds it is z minutes earlier compared to the usual.

     

    Alice is good at math. She wants to challenge her dad with some questions.

    Now she gives two numbers of x, y, z and asks his father to calculate the third one.

     

    For example, she says “dad, when y equals 30, and z equals to 20, what’s the x?”

    Fzz gives the answer ‘40’ right after the question.

    However it’s your turn. Can you calculate it?

    Input
    The input contains several cases.
    First line contains an integer n, the number of test cases (n<=10000).
    For each case, there are 2 integers and 1 character ‘?’. The first stands for x, the second stands for y, and the third stand for z.
    Output
    For each case, output in a single line with the answer to the ‘?’. It is guaranteed all the number will be positive integer no more than 1000000 (both Input & output).
    Sample Input
    3
    ? 30 20
    40 ? 20
    40 30 ?
    Sample Output
    40
    30
    20
    Hint
     
    Source

    这道题我题目都没看,队友敲的

    先贴代码= =

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<queue>
    #include<algorithm>
    //const int maxn;
    using namespace std;
    char s[1000];
    int num[5];
    int main(){
        int n;
        int i,j,k;
        int que;
        scanf("%d",&n);
        while(n--)
        {
          int cnt=0;
          for(i=0;i<3;i++)
          {
            scanf("%s",s);
            if(s[0]!='?')
            {
              int temp=0;
              int wei=1;
              for(j=strlen(s)-1;j>=0;j--)
              {
                temp+=(s[j]-'0')*wei;
                wei*=10;
              }
              num[i]=temp;
            }
            else que=i;
          }
    
          if(que==0)
          {
            num[0]=(num[2]+2*num[1])/2;
          }
          if(que==1)
          {
            num[1]=(2*num[0]-num[2])/2;
          }
          if(que==2)
          {
            num[2]=2*num[0]-2*num[1];
          }
          printf("%d
    ",num[que]);
    
        }
        return 0;
    }
    View Code
    Problem 1572 - I - Cyy and Fzz
    Time Limit: 1000MS   Memory Limit: 65536KB   
    Total Submit: 179  Accepted: 20  Special Judge: No
    Description
    As Cyy and Fzz are both busy repairing the network, Sama feel a little boring because it’s he who select Teemo during that game. Of cause his Teemo will stay alive since he has used the summoner spell Flash to avoid being killed. Since there is no network available, he wants to do something else to pass the time. He writes some strings randomly on the paper to kill the boring time.
    A few minutes later he realizes that what he writes on the paper is not truly random, in fact it reflects what he is concerned about. Then he comes up with a question, what is the expect number of interesting strings that will appear in the random string he writes? (The characters Sama writes are all lowercase Latin letters, in this problem we consider the probability that each character appears as the same, that is, 1/26)
    Input
    The first line is an integer T (T <= 13) indicates the case numbers.
    Then followed by T test cases. The first line of each test case contains two integers n and L(n <= 8, L <= 14), the number of interesting strings and the length of the string that Sama writes, then followed by n lines, the interesting strings. We promise that the interesting string is not longer than 12. (Notice that there may exist two or more same strings among the n interesting strings.)
    Output
    For each test case output one line, the expect number of interesting strings that will appear in the string Sama writes (Accurate to 6 digits after the decimal point).
    Sample Input
    3
    1 1
    a
    3 4
    cyy
    fzz
    sama
    8 14
    fatezero
    nisekoi
    nogamenolife
    monthlygirls
    nozakikun
    datealive
    sakura
    sora
    Sample Output
    0.038462
    0.000230
    0.000024
    Hint
     
    Source
     
    网上大牛题解
  • 相关阅读:
    hibernate悲观锁和乐观锁 Mr
    windows窗体调整
    我是一只草泥马
    草泥马2号
    用友二次开发 用友控件 Js宿主脚本 调用用友T6 登录 参照 控件示例
    KRBTabControl 不能不能输入
    藕のC#语法と
    ぇ份の测试ょ
    初学者编程入门:C语言指针使用方法
    开始写点东西了。。。。
  • 原文地址:https://www.cnblogs.com/clliff/p/4464277.html
Copyright © 2011-2022 走看看