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.
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(1≤T≤100)
, indicating the number of test cases. For each test case:
The first line contains two integer n and m (1≤m≤n≤500) . The second line contains n integers a1,a2,...,an (1≤ai≤1000) denoting Soda's cards. The third line contains n integers b1,b2,...,bn (1≤bi≤1000) denoting Beta's cards.
The first line contains two integer n and m (1≤m≤n≤500) . The second line contains n integers a1,a2,...,an (1≤ai≤1000) denoting Soda's cards. The third line contains n integers b1,b2,...,bn (1≤bi≤1000) 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
2 3 1 4 5 6 1 2 3 5 2 3 4 7 8 9 3 4 5 2 3
Sample Output
YES NO
Source
/************************************************************************/
附上该题对应的中文题
Card Game
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
Soda和Beta是好朋友. 今天他们准备要玩一个游戏. Soda有n张牌, 牌面上数字分别为a1,a2,...,an. Beta也有n张牌, 牌面上数字分别为b1,b2,...,bn. 一开始, 他们选择了一个小于等于n的数字m. 然后他们分别从自己的n张牌中随机选择了m张卡. m张卡的和大的那个人赢. Soda想要知道他是否能够必赢, 无论选出来的m张牌是什么.
输入描述
输入有多组数据. 第一行有一个整数T, 表示测试数据组数. 然后对于每组数据: 第一行有两个整数 n 和 m (1≤m≤n≤500). 第2行有n个整数a1,a2,...,an (1≤ai≤1000)表示Soda的牌. 第3行有n个整数b1,b2,...,bn (1≤bi≤1000)表示Beta的牌.
输出描述
对于每组数据, 如果Soda必赢输出"YES", 否则输出"NO".
输入样例
2 3 1 4 5 6 1 2 3 5 2 3 4 7 8 9 3 4 5 2 3
输出样例
YES NO
/****************************************************/
出题人的解题思路:
Problem 0. Card Game
由于都是随机出牌, Soda要必胜显然是他的最小的m张牌的和要大于Beta最大的m张牌的和.
因为是随机出牌,为了使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-10
using 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;
}
菜鸟成长记
1万+

被折叠的 条评论
为什么被折叠?



