A. Left-handers, Right-handers and Ambidexters
- 描述 :给左撇子,右撇子,左右手都会的人数。每个人只能用一只手,让你组一个最大人数的队,队中使用左手和右手的人数要平均。
- code
#include <bits/stdc++.h>
//#define LOCAL_DEFINE
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "rt", stdin);
#endif
int l, r, a;
cin >> l >> r >> a;
if(l > r) swap(l, r);
while(a) {
if(l < r) {
l++;
a--;
}
else {
r++;
a--;
}
}
cout << min(l, r) * 2 << endl;
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
- 描述给两组数(长度不同,和相同),求最大的n, 可以把第一组切分成n份,第二组切分成n份, 两组数对应的每一小份和要相同。
- 思路心得: 一开始没什么好想法就暴力。
AC后看别人的代码发现更巧妙的做法,把两组数前缀和存下来,如果有重复,ans++. 做水 题的意义除了自己思考,也在于发现别人巧妙的思路,不断学习,虽然好的思路往往不能直接想到,这时候瞎搞暴力的能力也很重要。 多练吧。
#include <bits/stdc++.h>
//#define LOCAL_DEFINE
using namespace std;
const int maxn = (int)1e5 + 10;
vector<int > v1(maxn), v2(maxn);
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "rt", stdin);
#endif
int n, m, t1 = 0, t2 = 0, k = 0, ans = 0;
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> v1[i];
for(int i = 0; i < m; i++) cin >> v2[i];
for(int i = 0; i < n; i++) {
t1 += v1[i];
if(t1 < t2 ) {
continue;
}
else if(t1 == t2) {
ans ++;
t1 = 0;
t2 = 0;
continue;
}
else if(t1 > t2){
for(int j = k; j < m; j++) {
t2 += v2[j];
if(t2 == t1) {
ans ++;
t1 = 0;
t2 = 0;
k = j + 1;
break;
}
else if( t2 > t1 && j < m - 1) {
k = j + 1;
break;
}
}
}
}
cout << ans << endl;
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a, b, cek[1001010], jum=0, x, ans=0;
int main(){
cin >> a>> b;
memset(cek, sizeof(cek), 0);
for(int i = 0; i <a ; i++) {
cin >> x;
jum += x;
cek[jum]++;
}
jum = 0;
for(int i = 0; i < b; i++) {
cin >> x;
jum += x;
if(cek[jum] > 0) ans++;
}
cout << ans << endl;
}