比赛链接 A 题解 知识点:贪心. 代码 #include <bits/stdc++.h> using namespace std; using ll = long long; bool solve() { int n; cin >> n; int cnt = 0; for (int i = 1;i <= n;i++) { int x; cin >> x; if (x == 1) cnt++; } int rst = n - cnt / 2 * 2; cout &
这是一道二分答案算法题,洛谷标签中的贪心等完全用不到. 这道题的数据范围较大,所以保险起见,整型的数据我们都开成longlong 题意很好理解,这里就不做过多的分析了,直接看代码,后面有注释: #include<bits/stdc++.h> using namespace std; long long n,k,l,a[1000010],maxn,ans; bool wood(long long x){ long long cnt=0; for(int i=1;i<=n;i++){ cnt