HDU 5494 Card Game(排个序就可以了)——BestCoder Round #58(div.2)

来源:互联网 发布:类似伊甸湖的电影知乎 编辑:程序博客网 时间:2024/06/01 10:17

Card Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


Problem Description
Soda and Beta are good friends. They are going to play a card game today. Soda has n cards with number a1,a2,...,an     while Beta has n cards with number b1,b2,...,bn.

First, they choose a number m no larger than n. Then they both randomly select m cards from their own n cards. The one with larger sum of the selected cards will win. Soda wants to know if he can always win no mater what cards will be randomly selected from him and Beta.
 

Input
There are multiple test cases. The first line of input contains an integer T(1T100), indicating the number of test cases. For each test case:

The first line contains two integer n and m (1mn500). The second line contains n integers a1,a2,...,an  (1ai1000)       denoting Soda's cards. The third line contains n integers b1,b2,...,bn  (1bi1000)       denoting Beta's cards.
 

Output
For each test case, output "YES" (without the quotes) if Soda can always win, otherwise output "NO" (without the quotes) in a single line.
 

Sample Input
23 14 5 61 2 35 23 4 7 8 93 4 5 2 3
 

Sample Output
YESNO
 

Source
BestCoder Round #58 (div.2)
 

/************************************************************************/

附上该题对应的中文题

Card Game

 
 
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
Soda和Beta是好朋友. 今天他们准备要玩一个游戏. Soda有nn张牌, 牌面上数字分别为a_1, a_2, ..., a_na1,a2,...,an. Beta也有nn张牌, 牌面上数字分别为b_1, b_2, ..., b_nb1,b2,...,bn.一开始, 他们选择了一个小于等于nn的数字mm. 然后他们分别从自己的nn张牌中随机选择了mm张卡. mm张卡的和大的那个人赢. Soda想要知道他是否能够必赢, 无论选出来的mm张牌是什么.
输入描述
输入有多组数据. 第一行有一个整数TT, 表示测试数据组数. 然后对于每组数据:第一行有两个整数 nnmm (1 \le m \le n \le 500)(1mn500). 第2行有nn个整数a_1, a_2, ..., a_na1,a2,...,an (1 \le a_i \le 1000)(1ai1000)表示Soda的牌. 第3行有nn个整数b_1, b_2, ..., b_nb1,b2,...,bn (1 \le b_i \le 1000)(1bi1000)表示Beta的牌.
输出描述
对于每组数据, 如果Soda必赢输出"YES", 否则输出"NO".
输入样例
23 14 5 61 2 35 23 4 7 8 93 4 5 2 3
输出样例
YESNO
/****************************************************/

出题人的解题思路:

Problem 0. Card Game

由于都是随机出牌, Soda要必胜显然是他的最小的mm张牌的和要大于Beta最大的mm张牌的和.

因为是随机出牌,为了使Soda随机抽取的m张牌之和一定比Beta随机抽取的m张牌之和大,那么要保证Soda拥有的n张牌中最小的m张牌之和需要大于Beta拥有的n张牌中最大的m张牌
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 505;const int inf = 1000000000;const int mod = 2009;int a[N],b[N];int main(){    int t,i,n,m,sum1,sum2;    scanf("%d",&t);    while(t--)    {        sum1=sum2=0;        scanf("%d%d",&n,&m);        for(i=0;i<n;i++)            scanf("%d",&a[i]);        for(i=0;i<n;i++)            scanf("%d",&b[i]);        sort(a,a+n);        sort(b,b+n);        for(i=0;i<m;i++)            sum1+=a[i];        for(i=0;i<m;i++)            sum2+=b[n-1-i];        if(sum1>sum2)            puts("YES");        else            puts("NO");    }    return 0;}
菜鸟成长记
0 0
原创粉丝点击