SRM 670 div2 A

Problem Statement

 

Two players are playing a cooperative game.

At the beginning of the game each player has some cards. There is a positive integer written on each card.

The game is played as follows:

  1. Each player chooses one of their cards.
  2. At the same time, each player gives the chosen card to the other player.
  3. Each player computes the sum of the numbers on the cards they now have.
  4. The final outcome of the game is the product of the two sums the players computed in the previous step.

You are given the vector <int>s a and b. The elements of a are the numbers on the first player's cards at the beginning of the game. The elements of b are the numbers on the second player's cards.

Compute and return the number of different outcomes the game may have.

Definition

 
Class:Cdgame
Method:rescount
Parameters:vector <int>, vector <int>
Returns:int
Method signature:int rescount(vector <int> a, vector <int> b)
(be sure your method is public)

Limits

 
Time limit (s):2.000
Memory limit (MB):256
Stack limit (MB):256

Constraints

-A and B will contain between 1 and 50 elements, inclusive.
-A and B will contain the same number of elements.
-Each element in A and B will be between 1 and 100, inclusive.

Examples

0) 
 
{1,2}
{3,4}
Returns: 2
This game can be played in four possible ways. One of them looks as follows:
  1. The first player chooses the card with the number 1. At the same time, the second player chooses the card with the number 3.
  2. Each player gives the chosen card to the other player. After the exchange the first player has the cards with numbers 2 and 3, and the second player has the cards with numbers 1 and 4.
  3. The first player computes that his sum is 2+3 = 5. The second player computes that her sum is 1+4 = 5.
  4. The final outcome is the value 5*5 = 25.
The other three ways correspond to the following outcomes: (2+4)*(1+3) = 6*4 = 24, (1+3)*(2+4) = 4*6 = 24, and (1+4)*(2+3) = 5*5 = 25. Hence, only two different outcomes are possible: 24 and 25. Thus, the correct return value is 2.
1) 
 
{1,2,4}
{8,16,32}
Returns: 9
With three cards in each player's hand there are 9 ways to play the game. In this case each of those ways leads to a different outcome.
2) 
 
{1,1,1}
{1,1,1}
Returns: 1
Again, there are 9 ways to play the game, but obviously in this case the outcome will always be the same.
3) 
 
{1,2,3}
{5,5,5}
Returns: 3
4) 
 
{3,3,4,1}
{2,2,2,100}
Returns: 4

5) 
 
{31,34,55,56,57}
{1,2,3,4,5}
Returns: 15

一个这么简单的题目搞了半天,主要是题意不懂。

英语不好,就是这样。

题意:有两个人,每个人手上有n个卡片。每个人拿对方的一张卡片,然后求每个人手上卡片上数的和,再求他们的积。输出积有多少种可能。

比如样例一: (2+4)*(1+3) = 6*4 = 24, (1+3)*(2+4) = 4*6 = 24, and (1+4)*(2+3) = 5*5 = 25,(2+3)*(1+4)=25

直接模拟。

时间复杂度O(n^2)

#include
   
   
    
    
#include
    
    
     
     
#include
     
     
      
      
#include
      
      
       
       
#include
       
       
         #include 
         using namespace std; class Cdgame { public: int rescount(vector 
         
           a, vector 
          
            b) { int ans = 0; int i, j, k; map 
           
             g; int sum1 = 0, sum2 =0; for(i = 0; i < a.size(); i++) { sum1 += a[i]; } for(i = 0; i < b.size(); i++) { sum2 += b[i]; } for(i = 0; i < a.size(); i++) { for(j = 0; j < b.size(); j++) { int tmp = (sum1 - a[i] + b[j]) * (sum2 + a[i] - b[j]); if(!g[tmp]) { ans++; g[tmp]=1; } } } return ans; } }; 
            
           
          
       
      
      
     
     
    
    
   
   


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值