[日常水题 3.15] codeforces 950 A - B

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;    
}  

B. Intercepted Message

  • 描述给两组数(长度不同,和相同),求最大的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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值