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 i th player’s strength point is ai .
If there is a match between thei th player plays and the j th player, the result will be related to |ai−aj| . If |ai−aj|>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. Aftern−1 matches, the last player will be the winner.
Now, Yuta shows the numbersn,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?
A wrestling match will be held tomorrow.
If there is a match between the
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
Now, Yuta shows the numbers
It is too difficult for Rikka. Can you help her?
Input
The first line contains a number t(1≤t≤100) , the number of the testcases. And there are no more than 2 testcases with n>1000 .
For each testcase, the first line contains two numbersn,K(1≤n≤105,0≤K<109) .
The second line containsn numbers ai(1≤ai≤109) .
For each testcase, the first line contains two numbers
The second line contains
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 graphG 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 graphG (wG ) as ∑ni=1∑nj=1dist(i,j) .
Now, Yuta hasn nodes, and he wants to choose no more than m pairs of nodes (i,j)(i≠j) 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 ofwG .
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) .
For an undirected graph
Then, we can define the weight of the graph
Now, Yuta has
Yuta wants to know the minimal value of
It is too difficult for Rikka. Can you help her?
In the sample, Yuta can choose
Input
The first line contains a number t(1≤t≤10) , the number of the testcases.
For each testcase, the first line contains two numbersn,m(1≤n≤106,1≤m≤1012) .
For each testcase, the first line contains two numbers
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 hasn positive A1−An and their sum is m . Then for each subset S of A , Yuta calculates the sum of S .
Now, Yuta has got2n numbers between [0,m] . For each i∈[0,m] , he counts the number of i s he got as Bi .
Yuta shows Rikka the arrayBi and he wants Rikka to restore A1−An .
It is too difficult for Rikka. Can you help her?
Yuta has
Now, Yuta has got
Yuta shows Rikka the array
It is too difficult for Rikka. Can you help her?
Input
The first line contains a number t(1≤t≤70) , the number of the testcases.
For each testcase, the first line contains two numbersn,m(1≤n≤50,1≤m≤104) .
The second line containsm+1 numbers B0−Bm(0≤Bi≤2n) .
For each testcase, the first line contains two numbers
The second line contains
Output
For each testcase, print a single line with n numbers A1−An .
It is guaranteed that there exists at least one solution. And if there are different solutions, print the lexicographic minimum one.
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 1HintIn 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"); }}
阅读全文
0 0
- 2017 多校系列 5
- 2017 多校系列 1
- 2017 多校系列 2
- 2017 多校系列 3
- 2017 多校系列 4
- 2017 多校系列 6
- Learning python 系列5
- [SilkyBible] XviD系列-5
- XNA系列(5)
- 5件事系列
- 计算机基础知识扫盲系列5
- 系列5:创建警报
- 算法系列5《SSF33》
- xshell xftp 5系列
- Leetcode--easy系列5
- greenDAO系列5--查询
- Craftyjs系列5-Audio
- laravel系列5-- 中间件
- __cxa_call_unexpected原因
- 对于自编译Ueditor问题
- 【Java实战】Java实现简易坦克对战小游戏
- javaseday21(缓冲区 为什么弄个int 和 char[] readLine 的实现原理 如何自己实现)
- js jq中$().eq()和$().find()的用法
- 2017 多校系列 5
- 假设检验与参数估计的R语言实现
- 【Java实战】Java实现简易音乐播放器
- Win7下32位Python2.7 安装Numpy+Scipy过程
- LintCode 前序遍历和中序遍历树构造二叉树
- linux netstat命令简介
- java.lang.ClassCastException: net.sf.json.JSONNull cannot be cast to net.sf.json.JSONObject
- 批量插入数据库
- 服务器返回JSONObjtect数据,前段收到的却是HTML