SRM 670 DIV 2 Cdgame 250-point
2015-10-12 10:10
375 查看
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:
Each player chooses one of their cards.
At the same time, each player gives the chosen card to the other player.
Each player computes the sum of the numbers on the cards they now have.
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 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 , vector
Returns:
int
Method signature:
int rescount(vector a, vector 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:
The first player chooses the card with the number 1. At the same time, the second player chooses the card with the number 3.
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.
The first player computes that his sum is 2+3 = 5. The second player computes that her sum is 1+4 = 5.
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
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
My Solution
#include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <map> #include <set> using namespace std; class Cdgame { public: int rescount(vector <int> a, vector <int> b) { set<int> s; int asum = 0, bsum = 0; for (int i = 0; i < a.size(); i++) asum += a[i]; for (int i = 0; i < b.size(); i++) bsum += b[i]; for (int i = 0; i < a.size(); i++) for (int j = 0; j < b.size(); j++) s.insert((asum - a[i] + b[j]) * (bsum - b[j] + a[i])); return s.size(); } };
相关文章推荐
- 概率最大骰子总和 Topcoder SRM 536 DIV1 第2题
- TopCoder SRM 569 DIV2 Level3: MegaFactorialDiv2
- Topcoder SRM Div2 Level2
- Topcoder SRM 547 DIV1 Level 1: Pillars
- TopCoder SRM DIV2 Level 3: RelativelyPrimeSubset
- TopCoder SRM 558 DIV2 Level 3:CatAndRabbit
- Topcoder SRM642 TaroCutting
- topcoder arena 插件配置
- Convert from char to int OR Convert from int to char
- Topcoder Open 2014 Algorithm Round 1A
- TopCoder SRM 593: MayTheBestPetWin 势均力敌的赛跑
- TopCoder SRM 610: The Matrix 区分现实与梦境的棋盘
- Topcoder/SRM565
- TOPCODER/SRM565 DIVII 250、500pt(500pt无递归解法)
- TOPCODER/SRM 566 DIVII(250、500、1000题)(1000PT暂未附上代码)
- TOPCODE/SRM567 DIVII 250、500PT
- ACM-计算几何 #Topcoder #SRM187-DIV2 PointInPolygon
- TopCoder SRM 144 DIV2(200-point)
- TopCoder SRM 144 DIV2(550-point)
- ZigZag