小朋友学Codeforces(2):Round 454 DIV 2, A
2018-02-19 09:24
357 查看
题目
907A. Masha and Bears题意
人的体积为VV,车的大小为sizesize,人能钻进车的条件是V≤sizeV≤size,人对车满意的条件是2V≥size2V≥size.现知道
熊爸爸能钻进最大的车并且满意
熊妈妈能钻进中等的车并且满意
熊宝宝能钻进最小的车并且满意
Masha能钻进最小的车并且只对它满意
给定四人的体积(保证V1>V2>V3),要求给出三辆车的大小。
解法(一)
思路:假设三辆车大小分别为a,b,c,则有
V1≤a≤2V1//熊爸爸
V2≤b≤2V2//熊妈妈
V3≤c≤2V3//熊宝宝
V4≤c≤2V4//Masha
2V4
#include <bits/stdc++.h> using namespace std; int main() { int x1, x2, x3, x4; scanf("%d %d %d %d", &x1, &x2, &x3, &x4); int ans1 = 2 * x1; int ans2 = 2 * x2; int ans3; if (x3 == x4) { ans3 = x3; } else if (x3 > x4) { if (x3 <= 2 * x4) { ans3 = x3; } else { ans3 = -1; } } else { if (x4 <= 2 * x3) { ans3 = x4; } else { ans3 = -1; } } if (ans3 == -1) { puts("-1"); } else { if (2 * x4 < ans2) { printf("%d\n%d\n%d\n", ans1, ans2, ans3); } else { puts("-1"); } } return 0; }
运行结果:
50 30 10 10 100 60 10
解法(二)
思路:每辆车对熊来说有下面三种可能:
不能进去的车V>C;
能进去但不喜欢的车V<2V
#include <stdio.h> #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)>(b)?(b):(a)) int main() { int father, mother, son, masha; int car1, car2, car3; scanf("%d %d %d %d", &father, &mother, &son, &masha); bool flag = false; for (car3 = max(son, masha); car3 <= min(2 * son, 2 * masha) && false == flag; ++car3) { for (car2 = max(mother, max(car3 + 1, 2 * masha + 1)); car2 <= 2 * mother && false == flag; ++car2) { for (car1 = max(father, max(car2 + 1, 2 * masha + 1)); car1 <= 2 * father && false == flag; ++car1) { flag = true; printf("%d\n%d\n%d", car1, car2, car3); } } } if (flag == false) { printf("-1"); } return 0; }
运行结果:
50 30 10 10 50 30 10
更多内容请关注微信公众号
相关文章推荐
- 小朋友学Codeforces(1):Round 453 DIV 2, A
- 小朋友学Codeforces(3):Round 453 DIV 2, B
- 小朋友学Codeforces(4):Round 453 DIV 2, C
- 小朋友学Codeforces(5):Round 453 DIV 2, 902D
- Codeforces 584 C. Marina and Vasya (Codeforces Round #324 (Div. 2))
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
- Codeforces-Round-#357-(Div.-2)-Heap-Operations
- Codeforces Round #454 (Div. 2)
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
- Codeforces 584 D. Dima and Lisa ( Codeforces Round #324 (Div. 2))
- Codeforces Round #425 (Div. 2) Problem D Misha, Grisha and Underground (Codeforces 832D) - 树链剖分 - 树状数组
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
- Codeforces-Round-#357-(Div.-2)-A-Good-Contest
- Codeforces 453 B Little Pony and Harmony Chest(Round 259 div.1 B/div.2 D)
- Codeforces-Round-#357-(Div.-2)-Economy-Game
- 【codeforces】Codeforces Round #277.5 (Div. 2)
- Codeforces - Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)C - Constellation
- 【codeforces】AIM Tech Round 3 (Div. 2)
- 【Codeforces Round 364 (Div 2)D】【二分答案 or 公式推导】As Fast As Possible 小朋友乘校车去远足最短到达时间
- codeforces(Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) )(C,D)