Equal Total Scores
Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which?
Note that they have to exchange their cards even if they already have cards of the same total score.
Input
The input consists of a number of datasets. Each dataset is formatted as follows.
n m
s1
s2
...
sn
sn+1
sn+2
...
sn+m
The first line of a dataset contains two numbers n and m delimited by a space, where n is the number of cards that Taro has and m is the number of cards that Hanako has. The subsequent n+m lines list the score for each of the cards, one score per line. The first n scores (from s1 up to sn) are the scores of Taro's cards and the remaining m scores (from sn+1 up to sn+m) are Hanako's.
The numbers n and m are positive integers no greater than 100. Each score is a nonnegative integer no greater than 100.
The end of the input is indicated by a line containing two zeros delimited by a single space.
Output
For each dataset, output a single line containing two numbers delimited by a single space, where the first number is the score of the card Taro gives to Hanako and the second number is the score of the card Hanako gives to Taro. If there is more than one way to exchange a pair of cards that makes the total scores equal, output a pair of scores whose sum is the smallest.
In case no exchange can make the total scores equal, output a single line containing solely 1. The output must not contain any superfluous characters that do not conform to the format.
Sample Input
2 2
1
5
3
7
6 5
3
9
5
2
3
3
12
2
7
3
5
4 5
10
0
3
8
1
9
6
0
6
7 4
1
1
2
1
2
1
4
2
3
4
3
2 3
1
1
2
2
2
0 0
Output for the Sample Input
1 3
3 5
1
2 2
1
 点赞
 写回答
 关注问题
 收藏
 复制链接分享
 邀请回答
2条回答

采纳
点赞 评论 复制链接分享

采纳
点赞 评论 复制链接分享
相关推荐
 回答 2 已采纳 Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which? Note that they have to exchange their cards even if they already have cards of the same total score. Input The input consists of a number of datasets. Each dataset is formatted as follows. n m s1 s2 ... sn sn+1 sn+2 ... sn+m The first line of a dataset contains two numbers n and m delimited by a space, where n is the number of cards that Taro has and m is the number of cards that Hanako has. The subsequent n+m lines list the score for each of the cards, one score per line. The first n scores (from s1 up to sn) are the scores of Taro's cards and the remaining m scores (from sn+1 up to sn+m) are Hanako's. The numbers n and m are positive integers no greater than 100. Each score is a nonnegative integer no greater than 100. The end of the input is indicated by a line containing two zeros delimited by a single space. Output For each dataset, output a single line containing two numbers delimited by a single space, where the first number is the score of the card Taro gives to Hanako and the second number is the score of the card Hanako gives to Taro. If there is more than one way to exchange a pair of cards that makes the total scores equal, output a pair of scores whose sum is the smallest. In case no exchange can make the total scores equal, output a single line containing solely 1. The output must not contain any superfluous characters that do not conform to the format. Sample Input 2 2 1 5 3 7 6 5 3 9 5 2 3 3 12 2 7 3 5 4 5 10 0 3 8 1 9 6 0 6 7 4 1 1 2 1 2 1 4 2 3 4 3 2 3 1 1 2 2 2 0 0 Output for the Sample Input 1 3 3 5 1 2 2 1
 4年前回答 1 已采纳 Problem Description Given some cards each assigned a number, you're required to select EXACTLY K cards among them. While you select a card, I will check the number assigned to it and see if it satisfies some of the following conditions: 1. the number is a prime number; 2. the amount of its divisors is a prime number; 3. the sum of its divisors is a prime number; 4. the product of all its divisors is a perfect square number. A perfect square number is such a kind of number that it can be written as a square of an integer. The score you get from this card is equal to the amount of conditions that its number satisfies. The total score you get from the selection of K cards is equal to the sum of scores of each card you select. After you have selected K cards, I will check if there's any condition that has never been satisfied by any card you select. If there is, I will add some extra scores to you for each unsatisfied condition. To make the game more interesting, this score may be negative. After this, you will get your final score. Your task is to figure out the score of each card and find some way to maximize your final score. Note that 1 is not a prime number. In this problem, we consider a number to be a divisor of itself. For example, considering the number 16, it is not a prime. All its divisors are respectively 1, 2, 4, 8 and 16, and thus, it has 5 divisors with a sum of 31 and a product of 1024. Therefore, it satisfies the condition 2, 3 and 4, which deserves 3 points. Input The first line of the input contains the number of test cases T. Each test case begins with two integers N and K, indicating there are N kinds of cards, and you're required to select K cards among them. The next N lines describes all the cards. Each of the N lines consists of two integers A and B, which denote that the number written on this kind of card is A, and you can select at most B cards of this kind. The last line contains 4 integers, where the ith integer indicates the extra score that will be added to the result if the ith condition is not satisfied. The ABSOLUTE value of these four integers will not exceed 40000. You may assume 0<N≤103,0<K≤104,1≤A≤106,1≤B≤104,T≤40 and the total N of all cases is no more than 20000. In each case there are always enough cards that you're able to select exact K cards among them. Output Output two lines for each test case. The first line consists of N integers separated by blanks, where the ith integer is the score of the ith card. The second line contains a single integer, the maximum final scores you can get. Sample Input 1 5 3 1 1 2 1 3 1 4 1 5 1 1 2 3 4 Sample Output 1 3 2 2 2 11
 4年前回答 1 已采纳 Today football has become the most popular sport all over the world. Many countries have their own football league matches. And the FIFA wants to hold a great league match which could contains all the clubs throughout the world. It is difficult to rank so many teams just by hand. So they come to you for help. The rules of ranking are: 1. A team will get 3 points when they win a match, 1 point when get a draw, 0 point when lost. 2. Teams are ranked by their total points first. If two teams have the same points, the team who get the more "goal difference" ranks higher. "Goal difference" for a team is equal to the total number of balls they goal minus those they lost. 3. If two teams have both the same points and the same "goal difference", ranking them by their name alphabetically. Input The input contains many cases. The beginning of each case is a num m (m<=10000), which is the number of matches. The following m lines each give a score of a match. The format is: Team_name1 score1:score2 Team_name2 The length of team name is no more than 20 characters and the scores are less than 100. You may assume that every team in the league has taken part in at least one match. Output For each case output a ranking table, each team a line. The format of each line is Id Nm w d l Pt Gd "Id" is the index of the team starting from 1. "Nm" is the name of the team. "w", "d" and "l" respectively is the total number of matches the team win, draw and lost. "Pt" is the points of the team. And "Gd" is the team's goal difference. Use a single blank to separate all cases. Sample Input 4 Liverpool 1:0 ManchesterU ManchesterU 3:0 Leeds Arsenal 2:2 Liverpool Leeds 1:5 Arsenal 6 RealMadrid 3:2 ACMilan ZJGreenCity 3:2 RealMadrid ACMilan 1:4 ZJGreenCity RealMadrid 0:0 ZJGreenCity ACMilan 2:0 RealMadrid ZJGreenCity 3:3 ACMilan Sample Output 1 Arsenal 1 1 0 4 4 2 Liverpool 1 1 0 4 1 3 ManchesterU 1 0 1 3 2 4 Leeds 0 0 2 0 7 1 ZJGreenCity 2 2 0 8 4 2 ACMilan 1 1 2 4 2 3 RealMadrid 1 1 2 4 2
 回答 2 已采纳 The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points equal to the product of the number on the card taken and the numbers on the cards on the left and on the right of it. It is not allowed to take out the first and the last card in the row. After the final move, only two cards are left in the row. The goal is to take cards in such order as to minimize the total number of scored points. For example, if cards in the row contain numbers 10 1 50 20 5, player might take a card with 1, then 20 and 50, scoring 10*1*50 + 50*20*5 + 10*50*5 = 500+5000+2500 = 8000 If he would take the cards in the opposite order, i.e. 50, then 20, then 1, the score would be 1*50*20 + 1*20*5 + 10*1*5 = 1000+100+50 = 1150. Input The first line of the input file contains the number of cards N (3 <= N <= 100). The second line contains N integers in the range from 1 to 100, separated by spaces. Process to the end of file. Output Output file must contain a single integer  the minimal score. Sample Input 6 10 1 50 50 20 5 Sample Output 3650
 回答 1 已采纳 Description Following FIFA World Cup, a larger competition called "GIGA Universe Cup" is taking place somewhere in our universe. Both FIFA World Cup and GIGA Universe Cup are two rounds competitions that consist of the first round, also known as "group league", and the second called "final tournament." In the first round, participating teams are divided into groups of four teams each. Each team in a group plays a match against each of the other teams in the same group. For example, let's say we have a group of the following four teams, "Engband, Swedon, Argontina, and Nigerua." They play the following six matches: Engband  Swedon, Engband  Argontina, Engband  Nigerua, Swedon  Argontina, Swedon  Nigerua, and Argontina  Nigerua. The result of a single match is shown by the number of goals scored by each team, like "Engband 1  0 Argontina," which says Engband scored one goal whereas Argontina zero. Based on the result of a match, points are given to the two teams as follows and used to rank teams. If a team wins a match (i.e., scores more goals than the other), three points are given to it and zero to the other. If a match draws (i.e., the two teams score the same number of goals), one point is given to each. The goal difference of a team in given matches is the total number of goals it scored minus the total number of goals its opponents scored in these matches. For example, if we have three matches "Swedon 1  2 Engband," "Swedon 3  4 Nigerua," and "Swedon 5  6 Argontina," then the goal difference of Swedon in these three matches is (1 + 3 + 5)  (2 + 4 + 6) = 3. Given the results of all the six matches in a group, teams are ranked by the following criteria, listed in the order of priority (that is, we first apply (a) to determine the ranking, with ties broken by (b), with ties broken by (c), and so on). (a) greater number of points in all the group matches, (b) greater goal difference in all the group matches, (c) greater number of goals scored in all the group matches. If two or more teams are equal on the basis of the above three criteria, their place shall be determined by the following criteria, applied in this order: (d) greater number of points obtained in the group matches between the teams concerned, (e) greater goal difference resulting from the group matches between the teams concerned, (f) greater number of goals scored in the group matches between the teams concerned, If two or more teams are still equal, apply (d), (e), and (f) as necessary to each such group. Repeat this until those three rules to equal teams do not make any further resolution. Finally, teams that still remain equal are ordered by : (g) drawing lots by the Organizing Committee for the GIGA Universe Cup. The two teams coming first and second in each group qualify for the second round. Your job is to write a program which, given the results of matches played so far in a group and one team specified in the group, calculates the probability that the specified team will qualify for the second round. You may assume each team has played exactly two matches and has one match to play. In total, four matches have been played and two matches are to be played. Assume the probability that any team scores (exactly) p goals in any match is: 8!/(P!(8  P)!)*(1/4)^p*(3/4)^(8p) , for p 8. Assume the lot in the step (g) is fair. Input The first line of the input is an integer, less than 1000, that indicates the number of subsequent records. The rest of the input is the indicated number of records. A single record has the following format: (empty) () (team)1 () (team)2 () (team)3 () (team)4 (team)1 () (empty) () (m)12 () (m)13 () (m)14 (team)2 () (empty) () (empty) () (m)23 () (m)24 (team)3 () (empty) () (empty) () (empty) () (m)34 (team)4 () (empty) () (empty) () (empty) () (empty) In the above, () is a single underscore () and (empty) a sequence of exactly four underscores (____). Each of (team)1,?,(team)4 is either an asterisk character (*) followed by exactly three uppercase letters (e.g., *ENG) , or an underscore followed by exactly three uppercase letters (e.g., _SWE). The former indicates that it is the team you are asked to calculate the probability of the second round qualification for. You may assume exactly one of (team)1,?, (team)4 is marked with an asterisk. Each (m)ij (1 <= i < j <= 4) is a match result between the (team)i and (team)j. Each match result is either ___ (i.e., two underscores, hyphen, and another underscore) or of the form _xy where each of x and y is a single digit (<= 8). The former indicates that the corresponding match has not been played, whereas the latter that the result of the match was x goals by (team)i and y goals by (team)j. Since each team has played exactly two matches, exactly two match results are in the former format. Output The output should consist of n lines where n is the number of records in the input. The ith line should show the probability that the designated team (marked with an asterisk) will qualify for the second round in the ith record. Numbers should be printed with exactly seven digits after the decimal point. Each number should not contain an error greater than 10^(7). Sample Input 5 _____*AAA__BBB__CCC__DDD *AAA_______00__00____ _BBB________________00 _CCC_________________00 _DDD____________________ ______CHN__CRC__TUR_*BRA _CHN_______02______04 _CRC____________11____ _TUR_________________12 *BRA____________________ ______CMR_*KSA__GER__IRL _CMR_______10______11 *KSA____________08____ _GER_________________11 _IRL____________________ ______TUN__JPN_*BEL__RUS _TUN___________11__02 _JPN____________22__10 *BEL___________________ _RUS____________________ ______MEX__CRO_*ECU__ITA _MEX_______10__21____ _CRO________________21 *ECU_________________02 _ITA____________________ Sample Output 0.5000000 1.0000000 0.0000000 0.3852746 0.0353304
 Blankj的博客 Description Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card
 ACM弱渣的平凡之路的博客 Equal Total Scores Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Submit Status Description Taro and Hanako have numbers of cards in their hand
 scriptkids的博客 这道题题意很简单,水题一道,就是说两个人手里有张数未必相同的扑克牌,问,能否通过两人交换一张牌来实现两人手中的牌的和相等,如果可以输出这两张牌,不可以则输出1值得注意的是,如果交换之前两人手中的牌的和已经相等,扔需经过一次交换.比较简单,代码就不写注释了#include #define INT_MAX 20000 int main(void) { int n,m,status,i,j,score_1,score_2,sum; int a[250],b[250]; while (scan
 Wss0130的博客 #include #define MAX 0x7fffffff int main() { int i,j,t1,t2,s1,s2,f,s,m,n,flag,min; int a[1000],b[1000]; while(scanf("%d%d",&n,&m)!=EOF) { if(m==0&&n==0) break; s1=0; s2=0; flag=0; t1=
 索儿呀的博客 1. 这本书对Python的知识点的描述很详细，而且排版看的很舒服. 2. 几个例题：假装自己从零开始学，将一些有代表性、有意思的例题抽取出来. 3. 还有自己对一部分课后复习题，全部课后上机实践题的解题思路
 pan_jinquan的博客 TensorFlow使用CNN实现中文文本分类 读研期间使用过TensorFlow实现过简单的CNN情感分析（分类），当然这是比较low的二分类情况，后来进行多分类情况。但之前的学习基本上都是在英文词库上训练的。断断续续，想整理一下手头的项目资料，于是就拾起读研期间的文本分类的小项目，花了一点时间，把原来英文文本分类的项目，应用在中文文本分类，效果还不错，在THUCNews中文数据集上，...
 weixin_26755331的博客 The linear programming technique (Data Envelopment Analysis) objectively determines the weights of evaluation criteria after suppliers are scored as opposed to the traditional process where the buyer ...
 6月前连理o的博客 本文为《Introduction to Probability》的读书笔记 目录Total Probability TheoremInference(推理) and Bayes' Rule Total Probability Theorem Example 1.15. Alice is taking a probability class and at the end of each week she can be either uptodate or she may have fallen behi
 3年前布客飞龙的博客 十、假设检验 原文：Testing Hypotheses 译者：飞龙 协议：CC BYNCSA 4.0 自豪地采用谷歌翻译 数据科学家们经常面对世界的是或不是的问题。你在这个课程中看到了一些这样的问题的例子： 巧克力对你有好处吗？ Broad Street 水泵的水是否会导致霍乱？ 加州的人口统计在过去的十年中有所改变吗？ 我们是否回答这些问题取决于我们的数据。
 DrogoZhang的博客 各种绘图实例 简单绘图 plot 函数： %matplotlib inline import numpy as np import matplotlib.pyplot as plt t = np.arange(0.0, 2.0, 0.01) s = np.sin(2*np.pi*t) plt.plot(t, s) plt.xlabel('time (s)') plt.ylabel('volt...
 布客飞龙的博客 TensorFlow Rager 教程 来源：madalinabuzau/tensorfloweagertutorials 译者：飞龙 协议：CC BYNCSA 4.0 一、如何使用 TensorFlow Eager 构建简单的神经网络 大家好！ 在本教程中，我们将使用 TensorFlow 的命令模式构建一个简单的前馈神经网络。 希望你会发现它很有用...
 一个处女座的程序猿的博客 NLP之词向量：利用word2vec对20类新闻文本数据集进行词向量训练、测试(某个单词的相关词汇) 目录 输出结果 设计思路 核心代码 输出结果 寻找训练文本中与morning最相关的10个词汇： [('afternoon', 0.8329864144325256), ('weekend', 0.7690818309783936), ('eveni...
 5年前刘迎光萤火虫工作室的博客 原文地址： http://www.cnblogs.com/greeenplace/articles/4667830.html PDF文件下载地址： http://download.csdn.net/detail/aradin/8440247 译者序 在做IT的公司里，尤其是软件开发部门，一般不会要求工程师衣着正式。在我工作过的一些环境相对宽松的公司里，很多程序员的衣着连得
 段智华的博客 计算机视觉系列全球小麦检测Kaggle比赛学习笔记trick专题 （9） 计算机视觉系列全球小麦检测Kaggle比赛学习笔记trick专题上集 （8）https://duanzhihua.blog.csdn.net/article/details/113398906 计算机视觉系列全球小麦检测Kaggle比赛学习笔记（7） https://duanzhihua.blog.csdn.net/article/details/113386405 目录 测试阶段trick总览PseudoLabellingM
 ciky奇的博客 本文主要针对SSD的tensorflow框架下的实现的源码解读即对网络模型的理解。 【前言】 首先在github上下载tensorflow版的SSD repository：https://github.com/balancap/SSDTensorflow 同时附上论文地址：SSD 论文下载 解压SSDTensorflowmaster.zip 到自己工作目录下。 S...