CF998A Balloons 构造
Balloons
算法:构造
rating : 1000
思路:
分情况讨论:
1. 当只有一个气球包时,肯定不行
2.当有两个气球包时,若两个气球包的气球个数相同则不行
3.其余的情况都是可以的,题目问给格里高利的气球包数量,以及选取得气球包的位置
除了情况1、2,只给格里高利第一个气球包,把其余的都给安德鲁,这样就省去选取得气球包的位置。
但是还需要进一步考虑这种情况,
3
3 2 1
这时候,如果给格里高利第一个气球包,则两个人拥有的气球数量就会相同。
因此我们在气球包中选取气球数量最小的气球包,以及该包所在的位置。
C++代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
int T,n;
int a[N];
void solve(){
cin >> n;
int minn = 101010;
int idx = -1;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(minn > a[i]){
minn = a[i];
idx = i;
}
}
if(n == 1){
cout << "-1" << endl;
return;
}
if(n == 2){
if(a[1] == a[2]){
cout << "-1" << endl;
return;
}
}
cout << 1 << endl;
cout << idx << endl;
return;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}