2424. Back and Forth

2424. Back and Forth topic description

Title description

Farmer John has two milking sheds, each with a milk tank and a locker containing 10 buckets of various sizes. He likes to transport milk back and forth between two milking sheds as a way of exercising.
On Monday, Farmer John measured exactly 1,000 gallons of milk in the milk tank of the first milking shed, and measured exactly 1,000 gallons of milk in the milk tank of the second milking shed.
On Tuesday, he took a bucket from the first milking shed and filled it with milk, then transported the milk to the second milking shed and poured the milk into the milk jug. He left the bucket in the second milking shed.
On Wednesday, he took a bucket from the second milking shed (probably left here on Tuesday) and filled it with milk, then transported the milk to the first milking shed and poured the milk into the milk jug. He left the bucket in the first milking shed.
On Thursday, he took a bucket from the first milking shed (probably left here on Wednesday) and filled it with milk, then transported the milk to the second milking shed and poured the milk into the milk jug. He left the bucket in the second milking shed.
On Friday, he took a bucket from the second milking shed (may be left here on Tuesday or Thursday) and filled it with milk, then transported the milk to the first milking shed and poured the milk into Milk jug. He left the bucket in the first milking shed.
At this time Farmer John measured the milk in the milk tank of the first milking shed. How many different readings might he get in total?

Input

The first line of input contains 10 integers, which are the initial bucket volume in the first milking shed. The second line of input also contains 10 integers, which are the initial bucket volume in the second milking shed. The volume of all barrels is in the range of 1 ... 100.

Output

Output the number of readings that Farmer John might get when measuring the milk in the milk jug in the first milking shed after Friday.

Sample input

1 1 1 1 1 1 1 1 1 2
5 5 5 5 5 5 5 5 5 5

Sample output

5

Data range limitation

Tip
In this example, there are a total of 5 possible results for the amount of milk in the milk tank of the first milking shed:
1000: FJ can carry the same bucket every time it travels, so it will not change the first The amount of milk in the milk cans of a milking shed.
1003: FJ can ship 2 units on Tuesday, 5 units on Wednesday, 1 unit on Thursday, and 1 unit on Friday.
1004: FJ can ship 1 unit on Tuesday, 5 units on Wednesday, 1 unit on Thursday, and 1 unit on Friday.
1007: FJ can ship 1 unit on Tuesday, 5 units on Wednesday, 2 units on Thursday, and 5 units on Friday.
1008: FJ can ship 1 unit on Tuesday, 5 units on Wednesday, 1 unit on Thursday, and 5 units on Friday.

Idea: The
subject can be simplified as follows: there is a variable X with an initial value of 1000. We can think of the buckets in the two milking sheds as the elements in the a and b arrays, and performed four operations (-+- +, See the specific meaning). Finally, ask how many different values ​​X has after the operation.
The difficulty of this question is how to enumerate all the operations.
Think about it carefully, although there are super varieties, but based on only twenty kinds of elements, and each element is not large (1 ~ 100). So we can consider using violence.
There are actually only three kinds of operations:

  1. All white dry (carry the same bucket every time you travel)
  2. Do it twice (the principle is the same as above, only two days of work)
  3. Give two, also two (bottle numbers are different)

The first two are easy to understand, and the third requires permutation and combination (the principle of multiplication)

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
using namespace std;
const int MAX=2147483647;
const int N=1e2;
int a[N],b[N],ans;
bool vis[2000];
void input()
{
	for(int i=1;i<=10;i++) scanf("%d",&a[i]);
	for(int i=1;i<=10;i++) scanf("%d",&b[i]);
}
void work()
{
	vis[1000]=1; //白干
	for(int i=1;i<=10;i++) //有两天白干 
	for(int j=1;j<=10;j++) 
		vis[1000-a[i]+b[j]]=1;
		
	for(int i=1;i<=9;i++)	//给两个,还两个(桶号都不同) 
	for(int j=1;j<=9;j++)
	for(int x=i+1;x<=10;x++)
	for(int y=j+1;y<=10;y++)
		vis[1000-a[i]+b[j]-a[x]+b[y]]=1;
		
	for(int i=800;i<=1198;i++) 
	if(vis[i]) ans++;
}
int main()
{
	//fre(backforth);
	input();
	work();
	printf("%d",ans);
	return 0;
}
Published 130 original articles · praised 93 · visits 6791

Guess you like

Origin blog.csdn.net/bigwinner888/article/details/105603231