Atcoder4105 Same Integers(模拟)

https://abc093.contest.atcoder.jp/tasks/arc094_a?lang=en

思路题还是不太会做哈。感觉数据不大,一开始dfs做但是发现不是最优解,一想确实是这么一回事,然后转bfs,但是测第三组数据的时候就能看出来超时了。

其实这题仔细想想,只有两种情况最小值+2,一是大、中值相等时,如果最小值+2可以达到全部相等,或者比另两个大1然后另两个各+1;二是大值比小值大超过1,最后会达到一所说的局面。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cstdlib>
 6 #include<cmath>
 7 #include<vector>
 8 #include<queue>
 9 #define IO ios::sync_with_stdio(false);cin.tie(0);
10 const int MOD=1e9+7;
11 typedef long long ll;
12 using namespace std;
13 int a[3], cnt=0;
14 int main()
15 {
16     for(int i = 0; i < 3; i++){
17         cin >> a[i];
18     }
19     sort(a, a+3);
20     while(a[0] != a[2]){
21         cnt++;
22         if(a[1] == a[2] || a[2]-a[0]>1)
23             a[0] += 2;
24         else a[0]++, a[1]++; 
25         sort(a, a+3);
26     }
27     cout << cnt << endl;
28     return 0;
29 } 
原文地址:https://www.cnblogs.com/Surprisezang/p/8763662.html