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

Integer slices are a way to extract a subset of elements from a list or array of integers. In Python, you can use the slice notation to extract a range of elements from a list or array. For example: ``` my_list = [1, 2, 3, 4, 5] slice_1 = my_list[1:3] # returns [2, 3] slice_2 = my_list[2:] # returns [3, 4, 5] slice_3 = my_list[:4] # returns [1, 2, 3, 4] ``` In the above examples, `my_list` is a list of integers. The slice notation `[1:3]` extracts the elements at index 1 and 2 (not including 3), which are `2` and `3`. The slice notation `[2:]` extracts all elements from index 2 to the end of the list. The slice notation `[:4]` extracts all elements from the beginning of the list up to (but not including) index 4. Integer slices can also be used with arrays of integers in languages such as C and Java. In these languages, you can use the array indexing notation to extract a range of elements from an array. For example: ``` int my_array[] = {1, 2, 3, 4, 5}; int slice_1[] = Arrays.copyOfRange(my_array, 1, 3); // returns [2, 3] int slice_2[] = Arrays.copyOfRange(my_array, 2, my_array.length); // returns [3, 4, 5] int slice_3[] = Arrays.copyOfRange(my_array, 0, 4); // returns [1, 2, 3, 4] ``` In the above examples, `my_array` is an array of integers. The `Arrays.copyOfRange` method is used to extract a range of elements from the array. The first argument is the array to extract from, the second argument is the starting index, and the third argument is the ending index (not including).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值