题面:

G. Back and Forth

Input file: standard input
Output file: 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 first barn, and exactly 1000 gallons of milk in the tank of the second barn.

On Tuesday, he takes a bucket from the first barn, fills 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), fills it, and carries the milk to the first barn, where he pours it into the storage tank. He leaves the bucket at the first barn.

On Thursday, he takes a bucket from the first barn (possibly the one he left on Wednesday), fills 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), fills it, and carries the milk to the first barn, where he pours it into the tank. He leaves the bucket at the first barn.

Farmer John then measures the milk in the tank of the first barn. How many possible different readings could he see?
 
Input
The first line of input contains 10 integers, giving the sizes of the buckets initially at the first 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 first 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 final amount of milk in the first barn’s tank:
  • 1000: FJ could carry the same bucket back and forth in each trip, leaving the total amount in the first 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 }
 
 

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

  1. 2019 GDUT Rating Contest II : Problem G. Snow Boots

    题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...

  2. 2019 GDUT Rating Contest II : Problem F. Teleportation

    题面: Problem F. Teleportation Input file: standard input Output file: standard output Time limit: 15 se ...

  3. 2019 GDUT Rating Contest III : Problem E. Family Tree

    题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...

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

    题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...

  5. 2019 GDUT Rating Contest III : Problem D. Lemonade Line

    题面: D. Lemonade Line Input file: standard input Output file: standard output Time limit: 1 second Memo ...

  6. 2019 GDUT Rating Contest I : Problem H. Mixing Milk

    题面: H. Mixing Milk Input file: standard input Output file: standard output Time limit: 1 second Memory ...

  7. 2019 GDUT Rating Contest I : Problem A. The Bucket List

    题面: A. The Bucket List Input file: standard input Output file: standard output Time limit: 1 second Me ...

  8. 2019 GDUT Rating Contest III : Problem A. Out of Sorts

    题面: 传送门 A. Out of Sorts Input file: standard input Output file: standard output Time limit: 1 second M ...

  9. 2019 GDUT Rating Contest II : Problem C. Rest Stops

    题面: C. Rest Stops Input file: standard input Output file: standard output Time limit: 1 second Memory ...

随机推荐

  1. 一句话木马的简单例子 网站webshell & 远程连接

    一  概述 本地 kail  linux 目标 windows nt 服务器 二 过程 首先编写一句话木马  index.php 一句话木马的原理就是把C=xxx 字符串当成php语句执行 注意这里用 ...

  2. Linux 网络协议栈开发基础篇—— 网桥br0

    一.桥接的概念 简单来说,桥接就是把一台机器上的若干个网络接口"连接"起来.其结果是,其中一个网口收到的报文会被复制给其他网口并发送出去.以使得网口之间的报文能够互相转发. 交换机 ...

  3. hdu 6242 Geometry Problem

    Geometry Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Other ...

  4. JavaScript调试技巧之console.log()

    与alert()函数类似,console.log()也可以接受变量并将其与别的字符串进行拼接: 代码如下: //Use variable var name = "Bob"; con ...

  5. ThinkCMF框架任意内容包含漏洞分析复现(写入shell+文件包哈)

    ThinkCMF框架任意内容包含漏洞分析复现 0x00 简介 ThinkCMF是一款基于PHP+MYSQL开发的中文内容管理框架,底层采用ThinkPHP3.2.3构建.ThinkCMF提出灵活的应用 ...

  6. Xcode 切换 iOS 模拟器的 Dark 模式

    Xcode 切换 iOS 模拟器的 Dark 模式 SwiftUI // // ContentView.swift // MemorizeGame // // Created by 夏凌晨 on 20 ...

  7. CSS style color all in one

    CSS style color all in one https://developer.mozilla.org/en-US/docs/Web/CSS/color_value /* Hexadecim ...

  8. queueMicrotask & EventLoop & macrotask & microtask

    queueMicrotask https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/queueMicro ...

  9. Open API collection

    Open API collection online API https://developer.github.com/v3/ https://developer.github.com/v4 http ...

  10. Flutter: 判断是Android还是Ios

    /// 在ui中使用下面的这个判断 Theme.of(context).platform == TargetPlatform.android /// 而不是 import 'dart:io' Plat ...