2019 GDUT Rating Contest I : Problem G. Back and Forth

题面:

G. Back and Forth

Input ?le: standard input

Output ?le: standard output

Time limit: 1 second

Memory limit: 256 megabytes

Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of various sizes. He likes to carry milk back and forth between the two barns as a means of exercise. On Monday, Farmer John measures exactly 1000 gallons of milk in the tank of the ?rst barn, and exactly 1000 gallons of milk in the tank of the second barn.

On Tuesday, he takes a bucket from the ?rst barn, ?lls it, and carries the milk to the second barn, where he pours it into the storage tank. He leaves the bucket at the second barn.

On Wednesday, he takes a bucket from the second barn (possibly the one he left on Tuesday), ?lls it, and carries the milk to the ?rst barn, where he pours it into the storage tank. He leaves the bucket at the ?rst barn.

On Thursday, he takes a bucket from the ?rst barn (possibly the one he left on Wednesday), ?lls it, and carries the milk to the second barn, where he pours it into the tank. He leaves the bucket at the second barn.

On Friday, he takes a bucket from the second barn (possibly the one he left on Tuesday or Thursday), ?lls it, and carries the milk to the ?rst barn, where he pours it into the tank. He leaves the bucket at the ?rst barn.

Farmer John then measures the milk in the tank of the ?rst barn. How many possible di?erent readings could he see?

Input

The ?rst line of input contains 10 integers, giving the sizes of the buckets initially at the ?rst barn. The second line of input contains 10 more integers, giving the sizes of the buckets initially at the second barn. All bucket sizes are in the range 1...100.

Output

Please print the number of possible readings Farmer John could get from measuring the milk in the tank of the ?rst barn after Friday.

Example

Input

1 1 1 1 1 1 1 1 1 2

5 5 5 5 5 5 5 5 5 5

Output

5

Note

In this example, there are 5 possible results for the ?nal amount of milk in the ?rst barn’s tank:

  • 1000: FJ could carry the same bucket back and forth in each trip, leaving the total amount in the ?rst barn’s tank unchanged.
  • 1003: FJ could carry 2 units on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 1 unit on Friday.
  • 1004: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 1 unit on Friday.
  • 1007: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 2 units on Thursday, and 5 units on Friday.
  • 1008: FJ could carry 1 unit on Tuesday, then 5 units on Wednesday, then 1 unit on Thursday, and 5 units on Friday.

题目描述:

农夫有两个奶牛棚,两个奶牛棚分别有一个牛奶缸和十个桶。两个牛奶缸刚开始都有1000加仑的牛奶。每过一天,农夫就会带一个桶从牛奶缸装满牛奶,走到另一个奶牛棚,然后把牛奶倒进这个牛奶棚牛奶缸。问过了这几天后,第一个牛奶缸可能有多少牛奶的情况的总数。

题目分析:

这道题我们直接模拟就可以了,题目数据不大。但是为了更好的简洁代码,我们还是分析一下题目有什么性质:

题目会有三种情况:

1.没有改变:

2.四天只有其中两天“交换”了桶:

3.四天中都“交换”了桶:

从上面我们可以看到,牛奶缸的变化量取决于“交换”的桶的差值。所以,我们在模拟的过程中记录桶的差值就可以得出有多少种情况,能达到某种情况就记录下来。

我们可以用c++ stl set来记录我们获得的情况(不知道为什么用数组记录不行??)。

对于第二种情况,前两天“交换”桶,后两天不“交换”桶 与 前两天不“交换”桶,后两天“交换”桶得到的情况是一样的。为了方便,我们只记录前者就行了。总的代码就是实现“交换”两次桶,用简单的循环就即可搞定。

AC代码:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <set>
 4 using namespace std;
 5 const int maxn = 1e4;
 6 int a[15], b[15];
 7 set<int> ans;
 8
 9 int main(){
10     for(int i = 0; i < 10; i++) cin >> a[i];
11     for(int i = 0; i < 10; i++) cin >> b[i];
12
13     ans.insert(1000);   //第一种情况
14     int d1, d2, t;
15     for(int i = 0; i < 10; i++){
16         for(int j = 0; j < 10; j++){
17             d1 = b[j]-a[i];   //差值
18
19             //交换桶
20             t = a[i];
21             a[i] = b[j];
22             b[j] = t;
23
24
25             for(int k = 0; k < 10; k++){
26                 for(int p = 0; p < 10; p++){
27                     d2 = b[p]-a[k];    //第二次不用交换, 直接算差值
28                     ans.insert(1000+d1+d2);   //第三种情况
29                 }
30             }
31             ans.insert(1000+d1);  //第二种情况
32
33             //换回来
34             t = a[i];
35             a[i] = b[j];
36             b[j] = t;
37
38         }
39     }
40
41     cout << ans.size() << endl;
42     return 0;
43 }

原文地址:https://www.cnblogs.com/happy-MEdge/p/10517186.html

时间: 2024-10-05 03:05:22

2019 GDUT Rating Contest I : Problem G. Back and Forth的相关文章

2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe

题面: C. Team Tic Tac Toe Input ?le: standard input Output ?le: standard output Time limit: 1 second Memory limit: 256 megabytes Farmer John owns 26 cows, which by happenstance all have names starting with different letters of the alphabet, so Farmer J

http://codeforces.com/contest/776/problem/G

题意: 讲一个16进制的数字num的每一位拆分下来 也就是sum = $\sigma(2 ^ a_i)$ 每一个a_i 都是不同的 举个栗子: $1014_16$ 就是 $2^1 + 2 ^ 0 + 2 ^ 4$ 求得的sum是个十进制的数字 然后将sum和num都化为二进制进行异或,如果异或后的值小于num那么++ans 现在题目是给出一个区间[l, r] 问这个区间内有多少个满足条件的数,也就是区间内ans的大小 思路: 贪心+数位dp, 定义三个状态 dp[mask1][mask2][le

2018 Multi-University Training Contest 3 1007 / hdu6325 Problem G. Interstellar Travel 凸包

Problem G. Interstellar Travel 题意: 给定平面上n个点,起点1 为(0,0),终点 n 为(Xn, 0),其它点的横坐标 0 <Xi<Xn,纵坐标 Xi >=0.每次可以飞到一个横坐标严格更大的点,代价为两个坐标的叉积.求起点到终点总代价最小的飞行路线,并输出字典序最小的路线.2≤n≤200000. Shortest judge solution: 979 bytes 题解: 显然坐标相同的点里只保留编号最小的点最优. 将起点到终点的路径补全为终点往下走到

http://codeforces.com/contest/575/problem/B

题目链接: http://codeforces.com/contest/575/problem/B 题解: 代码: #include<cstdio> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn = 1e5 + 10; const int DEG = 22; const in

HDU校赛 | 2019 Multi-University Training Contest 3

2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 1004. Distribution of books 考虑二分答案,设当前二分出来的是\(x\). 设\(f_i\)表示前\(i\)个能分成最多的段数,使得每一段和都\(\leqslant x\). 转移显然,枚举一个\(j\),若\(s_i-s_j\leqslant x\)则转移,\(s_i\)表示前

[最短路,最大流最小割定理] 2019 Multi-University Training Contest 1 Path

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6582 Path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3747    Accepted Submission(s): 1075 Problem Description Years later, Jerry fell in love

Problem G 宝石合成 (内蒙古14年省赛)

1117: Problem G 宝石合成 时间限制: 1 Sec  内存限制: 128 MB 提交: 18  解决: 4 [提交][状态][讨论版] 题目描述 故事人物:豆豆强 走上致富之路的豆豆强越来越有土豪范,买房买车已经提不起他的兴趣,现在玩起了魔法宝石. 这种宝石分为不同品质等级,并且3个品质等级为 i 的宝石,可以合成一个品质等级为 i+1 的宝石.更加神奇的是,不管这个宝石的品质怎么变,一个宝石永远只占一个单位的空间. 现在豆豆强需要买一个全金打造的保险柜来储存这些宝石.本来对于他这

http://codeforces.com/contest/741/problem/B B. Arpa&#39;s weak amphitheater and Mehrdad&#39;s valuable Hoses

题意: 给出上限体重W 然后还给出每个人的体重wi 和 魅力值 bi 互为伙伴的对(xi, yi) 可以凑成group 思路: 并查集找出所有的group 暴力背包 对于每一个group 要选出这一组内选一个人时的最优结果, 如果所有人的体重和小于等于W,还得考虑选所有人的情况 #include <iostream> #include <string.h> #include <algorithm> #include <stdio.h> #include &l

实验12:Problem G: 强悍的矩阵运算来了

这个题目主要是乘法运算符的重载,卡了我好久,矩阵的乘法用3个嵌套的for循环进行,要分清楚矩阵的乘法结果是第一个矩阵的行,第二个矩阵的列所组成的矩阵. 重载+,*运算符时,可以在参数列表中传两个矩阵引用,分别表示前后进行运算的矩阵,或者是只传运算符之后的矩阵引用,前一个矩阵用的是隐含的this指针指向的矩阵.我用的是后者. Home Web Board ProblemSet Standing Status Statistics Problem G: 强悍的矩阵运算来了 Problem G: 强悍