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

不会做,网上神牛代码膜拜一发

http://blog.csdn.net/Guard_Mine/article/details/45149137

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\n",sum+maxn);
    }
    return 0;
}

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\n",ans);
        }
    }
    return 0;
}

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\n",cnt);
    }
    return 0;
}

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

http://www.cnblogs.com/jklongint/p/4448539.html

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\n",ans);
    }
    return 0;
}

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\n",cnt);

    }return 0;
}

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\n",num[que]);

    }
    return 0;
}

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

网上大牛题解

http://blog.csdn.net/Guard_Mine/article/details/45149167

时间: 2024-08-06 20:19:37

15.4.19 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛的相关文章

第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛 Problem 1566 - C - Spanning Tree

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

第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛 A

Problem 1603 - Minimum Sum Time Limit: 2000MS   Memory Limit: 65536KB   Total Submit: 564  Accepted: 157  Special Judge: No Description There are n numbers A[1] , A[2] .... A[n], you can select m numbers of it A[B[1]] , A[B[2]] ... A[B[m]]  ( 1 <= B[

“盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛 B

<神无月>作为盛大游戏2017年的全新原创大作,其开发团队在自研实力强大的传世工作室基础之上,还有美树本晴彦等日本一线知名画师及日本游戏音乐大师崎元仁加盟参与制作.目前正在不限号内测中,有很多玩家进入到神无月的世界中. 在神无月中,有着玩家之间切磋的排位赛,其段位主要分为五大段位,从低到高依次为:新兵.菁英.战将.统帅.王者.每个玩家只有从新兵段位慢慢努力,一点点晋级才能到达王者段位.成为一个王者是每一个玩家的追求和心愿. 假设神无月的段位系统如下: 从低到高的段位依次简记为:D.C.B.A.

埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛 B合约数

链接:https://www.nowcoder.com/acm/contest/91/B来源:牛客网牛客网没有账号的同学,请用这个注册,支持楼主,谢谢. 题目描述 给定一棵n个节点的树,并且根节点的编号为p,第i个节点有属性值vali, 定义F(i): 在以i为根的子树中,属性值是vali的合约数的节点个数.y 是 x 的合约数是指 y 是合数且 y 是 x 的约数.小埃想知道对1000000007取模后的结果. 输入描述: 输入测试组数T,每组数据,输入n+1行整数,第一行为n和p,1<=n<

南昌大学航天杯第二届程序设计竞赛校赛网络同步赛 E

链接:https://www.nowcoder.com/acm/contest/122/E来源:牛客网 题目描述 愉快的周末到了,小C和他的N-1个朋友买了M个游戏,游戏编号从1~M.每个游戏都是多人游戏,他们打算周末一起打游戏. 小C的每个朋友都决定好了要玩哪一款游戏(会有一组人打同一款游戏),并且每人手上都有一台游戏机,这种游戏机可以通过特定的游戏机连接线连接起来. 但是,他们面临着一个问题:目前没有一个朋友的游戏机是互相连接的.所以它们必须用可用的游戏机连接线连接起来.小C决定依次使用第

Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). Then Alice as

sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛

Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees and flowers on the mountain, and there are many animals and birds also. Coco like the mountain so much that she now name some letter s

[2013山东省第四届ACM大学生程序设计竞赛]——Alice and Bob

Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1). T

[2013山东省第四届ACM大学生程序设计竞赛]——Rescue The Princess

Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immedia