hdoj KK's Number 5623 (DP)
来源:互联网 发布:迅捷网络官方登录网站 编辑:程序博客网 时间:2024/05/22 01:27
KK's Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 214 Accepted Submission(s): 128
Problem Description
Our lovely KK has a funny mathematical game:This game requires two people,There are N(1≤N≤5∗104) numbers,every time KK will take the numbers,first.Every time you can take any number of the numbers.Until the N number is taken.The minimum number of numbers is the score for each time.KK and the opponent's strategy is as much as possible to make their score minus the opponent's score more.In this case,How much is the final KK score minus the opponent's score?
Input
The first line of the input file contains an integer T(1≤T≤10) , which indicates the number of test cases.
For each test case, there are two lines,in the first line is a integerN(1≤N≤5∗104) ,the other line has N positive integers(no more than 109 ).
For each test case, there are two lines,in the first line is a integer
Output
For each test case, there are one lines,includes a integer,indicating the final KK's score minus the opponent's score.
Sample Input
131 3 1
Sample Output
2HintFirstly KK take 3;and the opponent take 1,1,so the result is 2.KK's Number
Accepts: 59Submissions: 137Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)问题描述我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N(1≤N≤5∗104)个数,每次KK都会先拿数。每次可以拿任意多个数,直到N个数被拿完。每次获得的得分为取的数中的最小值,KK和对手的策略都是尽可能使得自己的得分减去对手的得分更大。在这样的情况下,最终KK的得分减去对手的得分会是多少?输入描述第一行一个数T(1≤T≤10),表示数据组数。对于每组数据包含两行,第一行一个整数N(1≤N≤5∗104),表示个数,第二行N个正整数(不超过109)。输出描述对于每一个数据输出一个整数,表示最终KK的得分减去对手的得分。输入样例131 3 1输出样例2Hint首先KK取走3,然后对手取走两个1,那么最终分差为2。//思路:因为他们的得分都是他们取得的数中的最小的,所以取的分的个数不在于多。先将n个数排序,计算出两个数之间的最大间隔m,那么这个m即为所求。Hint:得有特殊判断,如果m小于a[0]的话就输出a[0](表示KK将所有数都拿走,对手分数为0)。(在这块WA了两次)。。。#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[50010];int main(){int t,i,j,n,m,k;scanf("%d",&t);while(t--){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);int m,ma=0;for(i=0;i<n;i++){m=a[i]-ma;ma=max(ma,m);}printf("%d\n",ma);}return 0;}
0 0
- hdoj KK's Number 5623 (DP)
- hdoj 5623 KK's Number 【dp】
- HDU 5623 KK's Number(DP)
- HDU 5623 KK's Number(dp)
- HDU 5623 KK's Number(博弈dp)
- HDU 5623 KK's Number(博弈dp)
- hdu 5623 KK's Number dp 博弈
- BestCoder Round #71 (div.2)-KK's Number(dp)
- HDU 5623 KK's Number
- hdu 5623 KK's Number
- 杭电5623KK's Number
- KK's Number
- HDOJ 5621 KK's Point
- hdoj-5620-KK's Steel
- hdoj--5621--KK's Point(简单数学)
- hdoj KK's Point 5621 (数学&规律)
- hdu 5623 KK's Number 动态规划 Bestcoder #71 1004
- HDU 5622 KK's Chemical(dp+组合数学)
- Git本地仓库与Github远程仓库关联
- ElasticSearch Rest/RPC 接口解析
- Android项目Tab类型主界面大总结 Fragment+TabPageIndicator+ViewPager
- linux常用基本命令之二十一 md5sum
- 不用证书进行真机测试
- hdoj KK's Number 5623 (DP)
- hibernate 默认连接池转c3p0
- 服务实体经济转型,正益工场技术助力“双创“落地
- wsprintf
- no CPU/ABI system image for target
- 正确使用SQL Server 2012中的SEQUENCE
- 【Android工具】svn ignore首次提交与非首次提交
- 创业之近日
- 字符串_过滤处理