2017 多校系列 5

来源:互联网 发布:php技术 编辑:程序博客网 时间:2024/06/05 23:53

Rikka with Competition

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 567    Accepted Submission(s): 453


Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

A wrestling match will be held tomorrow. n players will take part in it. The ith player’s strength point is ai.

If there is a match between the ith player plays and the jth player, the result will be related to |aiaj|. If |aiaj|>K, the player with the higher strength point will win. Otherwise each player will have a chance to win.

The competition rules is a little strange. Each time, the referee will choose two players from all remaining players randomly and hold a match between them. The loser will be be eliminated. After n1 matches, the last player will be the winner.

Now, Yuta shows the numbers n,K and the array a and he wants to know how many players have a chance to win the competition.

It is too difficult for Rikka. Can you help her?  
 

Input
The first line contains a number t(1t100), the number of the testcases. And there are no more than 2 testcases with n>1000.

For each testcase, the first line contains two numbers n,K(1n105,0K<109).

The second line contains n numbers ai(1ai109).
 

Output
For each testcase, print a single line with a single number -- the answer.
 

Sample Input
25 31 5 9 6 35 21 5 9 6 3
 

Sample Output
51
 

Source
2017 Multi-University Training Contest - Team 5
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6132 6131 6130 6129 6128 

题意:给你一堆数字,判断相差会不会小于K,记录有多少人可能赢。

题解:水题,sort一遍就好了


ac code:

#include<stdio.h>#include<algorithm>#include<math.h>#include<stdlib.h>#include<string.h>#include<string>//#include<iostream>//#include<vector>//#include<queue>//#include<stack>//#include<map>//#include<set>#define scand(x) scanf("%d",&x)#define scandd(x,y) scanf("%d%d",&x,&y)#define mst(a,zero) memset(a,zero,sizeof(a))#define PARITY(value) (value&1)/*value>0*/#define IsPowerOfTwo(n) ((!(n&(n-1)) ) && n)#define INF 0x3f3f3f3f#define intinf 1e9#define llinf 1e18#define eps 1e-8#define PI acos(-1.0)using namespace std;typedef long long LL;const int N=1e6+10;const int M=1e6+10;const int maxn=1e6+10;const int mod=1e9+7;int n,k;int a[100010];void solve(){int loser=0;sort(a,a+n);for (int i=0;i<n-1;i++){if (a[i+1]-a[i]>k)loser=i+1;}printf("%d\n",n-loser);}int main(){int T;scand(T);while(T--){scandd(n,k);for (int i=0;i<n;i++)scand(a[i]);//先特殊,后一般solve();}return 0;}


Rikka with Graph

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 841    Accepted Submission(s): 484


Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

For an undirected graph G with n nodes and m edges, we can define the distance between (i,j) (dist(i,j)) as the length of the shortest path between i and j. The length of a path is equal to the number of the edges on it. Specially, if there are no path between i and j, we make dist(i,j) equal to n.

Then, we can define the weight of the graph G (wG) as ni=1nj=1dist(i,j).

Now, Yuta has n nodes, and he wants to choose no more than m pairs of nodes (i,j)(ij) and then link edges between each pair. In this way, he can get an undirected graph G with n nodes and no more than m edges.

Yuta wants to know the minimal value of wG.

It is too difficult for Rikka. Can you help her?  

In the sample, Yuta can choose (1,2),(1,4),(2,4),(2,3),(3,4).
 

Input
The first line contains a number t(1t10), the number of the testcases. 

For each testcase, the first line contains two numbers n,m(1n106,1m1012).
 

Output
For each testcase, print a single line with a single number -- the answer.
 

Sample Input
14 5
 

Sample Output
14
 

Source
2017 Multi-University Training Contest - Team 5
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6132 6131 6130 6129 6128 

题解:主要是判断边的个数是否能将点与点之间两两相连,不行的话,就令一个点与其他全部点相连,如果不够边就成为孤立点,多一条边就减少1。


ac code:

#include<stdio.h>#include<algorithm>#include<math.h>#include<stdlib.h>#include<string.h>#include<string>//#include<iostream>//#include<vector>//#include<queue>//#include<stack>//#include<map>//#include<set>#define scand(x) scanf("%d",&x)#define scandd(x,y) scanf("%d%d",&x,&y)#define mst(a,zero) memset(a,zero,sizeof(a))#define PARITY(value) (value&1)/*value>0*/#define IsPowerOfTwo(n) ((!(n&(n-1)) ) && n)#define INF 0x3f3f3f3f#define intinf 1e9#define llinf 1e18#define eps 1e-8#define PI acos(-1.0)using namespace std;typedef long long LL;const int N=1e6+10;const int M=1e6+10;const int maxn=1e6+10;const int mod=1e9+7;LL n,m;void solve(){if (m+1<=n){LL ans=(n-1-m)*n*(m+1)*2+(n-1-m)*(n-2-m)*n;//孤立点ans+=(m+(2*m-1)*m);printf("%lld\n",ans);}else {//m+1>n,多了边if (n*(n-1)/2<=m){printf("%lld\n",n*(n-1));return;}LL ans=(n-1)*(2*n-2);LL d=m-(n-1);printf("%lld\n",ans-d*2);}}int main(){int T;scand(T);while(T--){scanf("%lld%lld",&n,&m);//先特殊,后一般solve();}return 0;}


Rikka with Subset

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1599    Accepted Submission(s): 812


Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has n positive A1An and their sum is m. Then for each subset S of A, Yuta calculates the sum of S

Now, Yuta has got 2n numbers between [0,m]. For each i[0,m], he counts the number of is he got as Bi.

Yuta shows Rikka the array Bi and he wants Rikka to restore A1An.

It is too difficult for Rikka. Can you help her?  
 

Input
The first line contains a number t(1t70), the number of the testcases. 

For each testcase, the first line contains two numbers n,m(1n50,1m104).

The second line contains m+1 numbers B0Bm(0Bi2n).
 

Output
For each testcase, print a single line with n numbers A1An.

It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
 

Sample Input
22 31 1 1 13 31 3 3 1
 

Sample Output
1 21 1 1
Hint
In the first sample, $A$ is $[1,2]$. $A$ has four subsets $[],[1],[2],[1,2]$ and the sums of each subset are $0,1,2,3$. So $B=[1,1,1,1]$
 

Source
2017 Multi-University Training Contest - Team 5
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6132 6131 6130 6129 6128 
题解:就是将B[i]推回A[i]。用动态规划来维护A[i]这个数组(01背包的思想)


ac code:

#include <sstream>#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s)  scanf("%s",s)#define pi1(a)    printf("%d\n",a)#define pi2(a,b)  printf("%d %d\n",a,b)#define mset(a,b)   memset(a,b,sizeof(a))#define forb(i,a,b)   for(int i=a;i<b;i++)#define ford(i,a,b)   for(int i=a;i<=b;i++)typedef long long LL;const int N=1e4+5;const int M=6666666;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-7;const int mod=998244353;int b[N],a[N],c[N],dp[N];int main(){    int t;    si1(t);    while(t--)    {        mset(dp,0);        mset(c,0);        mset(a,0);        int n,m;        si2(n,m);        for(int i=0;i<=m;i++)            si1(b[i]);        dp[0]=1;        int p=0;        for(int i=1;i<=m;i++)        {            c[i]=b[i]-dp[i];            for(int j=0;j<c[i];j++)            {                a[p++]=i;                for(int k=m;k>=i;k--)                {                    dp[k]+=dp[k-i];                }            }        }        printf("%d",a[0]);        for(int i=1;i<p;i++)            printf(" %d",a[i]);        printf("\n");    }}


原创粉丝点击