【codeforces 732C】 Sanatorium【乱搞题 数学题】
来源:互联网 发布:北师珠网络 编辑:程序博客网 时间:2024/05/19 04:29
传送门:C. Sanatorium
描述:
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.
3 2 1
1
1 0 0
0
1 1 1
0
1000000000000000000 0 1000000000000000000
999999999999999999
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
题意:
给你三个数,给这三个数循环定序,每次循环减一,为0的不能减的记录次数,最后输出多少次
思路:
分类讨论,不要漏情况,分类要合理
代码一:
#include <bits/stdc++.h>#define ll __int64using namespace std;ll mx, md, mn, x, y, z;void cal(){ll num[3];num[0] = x; num[1] = y; num[2] = z;sort(num, num+3);mn = num[0];md = num[1];mx = num[2];}int main(){cin>>x>>y>>z;cal();if(x == y && y == z){ cout<<0<<endl; }else if(x >= y && y <= z){//两边的数大于中间的数if(mx == 1)cout<<0<<endl; //特殊情况:当最大值为1时 else if(x == z)cout<<x - y - 1<<endl; //当两边值都相等时 else cout<<(mx - md - 1) * 2 + md - mn<<endl;}else{//两边的数至少有一个小于中间的数if(mx == md)cout<<md - mn -1<<endl; //特殊情况:最大值跟中间值相等时 else cout<<(mx - md - 1) * 2 + md - mn<<endl;}return 0;}
乱搞,这种乱搞题,尽量不要做烦,为后面的难题腾出一定的时间
代码二:
#include <bits/stdc++.h>#define ll __int64using namespace std;ll mx, md, mn, x, y, z;inline ll maz(ll a, ll b, ll c) {return max(a, max(b, c));}int main(){ll a, b, c;cin >> a >> b >> c;ll k = maz(a, b, c);ll ans = k - a + k - b + k - c;k = maz(a + 1, b, c);ans = min(ans, k - a - 1 + k - b + k - c);k = maz(a + 1, b + 1, c);ans = min(ans, k - a - 1 + k - b - 1 + k - c);k = maz(a, b, c + 1);ans = min(ans, k - a + k - b + k - c - 1);k = maz(a, b + 1, c + 1);ans = min(ans, k - a + k - b - 1 + k - c - 1);k = maz(b, a + 1, c + 1);ans = min(ans, k - b + k - a - 1 + k - c - 1);k = maz(b + 1, a, c);ans = min(ans, k - b - 1 + k - a + k - c);cout << ans;return 0;}
- 【codeforces 732C】 Sanatorium【乱搞题 数学题】
- codeforces 732C Sanatorium(数学题)
- [codeforces 732C]Sanatorium
- codeforces 732C - Sanatorium
- Codeforces 732C-Sanatorium
- CodeForces 732C Sanatorium
- CodeForces 732C Sanatorium
- Codeforces Round #377 (Div. 2) C. Sanatorium(规律乱搞)
- 【43.26%】【codeforces 732C】Sanatorium
- CodeForces 732C 之 Sanatorium
- CodeForces-732C-Sanatorium(模拟)
- CodeForces 732 C.Sanatorium(水~)
- 【codeforces 723C C. Sanatorium】
- Codeforces Round #377 (Div. 2)C. Sanatorium(想法题)
- 732C. Sanatorium
- Sanatorium Codeforces Round#377-C(逻辑)
- Codeforces Round #377 (Div. 2) C. Sanatorium
- Codeforces Round #377 (Div. 2) C Sanatorium
- C语言位操作
- 相机和镜头选型的关键:像素尺寸与景深
- Javascript跨域访问资源
- JAVA-RPC框架介绍
- 第五将项目2.4-输入圆柱体的高h和半径r输出圆柱体的表面积s
- 【codeforces 732C】 Sanatorium【乱搞题 数学题】
- html调用移动端系统功能
- Service总结
- 关于修改cc.EditBox的背景图片问题
- java中4大基本加密算法解析
- 如何为JLabel添加背景色和设置其imageicon的位置和大小
- 网络干货,无论是运维还是开发都要知道的网络知识系列
- linux下lz4解压缩遇到的那些事儿
- 思想实验(逻辑思维)解题