Codeforces 845 B Luba And The Ticket

编程入门 行业动态 更新时间:2024-10-09 06:30:15

<a href=https://www.elefans.com/category/jswz/34/1770097.html style=Codeforces 845 B Luba And The Ticket"/>

Codeforces 845 B Luba And The Ticket

题目地址
题意:给你一个6位的字符串,求改变数字的最小次数。
思路:就4种情况:(为了好写,我对于前三个和后三个按条件交换了顺序,和小的在前,和大的在后)

0、本来就相等
1、改变前三个中的最小的变为9的过程,或者改变后三个中最大的变为0的过程
2、改变前三个中的最小的和次小的变为9的过程,或者改变后三个中最大的和次大的变为0的过程,或者改变前三个中的最小的变为9的过程以及改变后三个中最大的变为0的过程
3、改变最小的三个

按这个要求写就好了。

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define N 110 
#define M 90010
#define LL __int64
#define inf 0x3f3f3f3f
#define lson l,mid,ans<<1
#define rson mid+1,r,ans<<1|1
#define getMid (l+r)>>1
#define movel ans<<1
#define mover ans<<1|1
using namespace std;
const LL mod = 1e9 + 7;
int num[N];
int main() {cin.sync_with_stdio(false);string str;int numa[3], numb[3], a, b;while (cin >> str) {a = 0, b = 0;for (int i = 0; i < 3; i++) {numa[i] = str[i] - '0';a += numa[i];}for (int i = 3; i < 6; i++) {numb[i-3] = str[i] - '0';b += numb[i - 3];}sort(numa, numa + 3);sort(numb, numb + 3);if (a > b) {swap(numa, numb);swap(a, b);}int num = b - a;if (a != b) {if (num <= 9 - numa[0] || num <= numb[2]) cout << 1 << endl;else if (num <= 18 - numa[0] - numa[1] || num <= numb[1] + numb[2] || num <= 9 - numa[0] + numb[2]) cout << 2 << endl;else cout << 3 << endl;}else {cout << 0 << endl;}}return 0;
}

更多推荐

Codeforces 845 B Luba And The Ticket

本文发布于:2024-02-19 16:27:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1764894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Codeforces   Ticket   Luba

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!