零点工作室暑假集训(AtCoder--ABC292)

Q1 A - CAPS LOCK
题意:给一个字符串,要求把小写字母改成大写。
分析: 循环模拟下就可以了,时间复杂度O ( n ) 

#include <iostream>

using namespace std;

string s;

int main()
{
    cin >> s;
    for(int i = 0; i < s.size(); i ++)
    {
        s[i] = s[i] - 32;
        cout << s[i];
    }
}

Q2 Yellow and Red Card
题意:有n个人,发生过q个事件,每个事件要么是某人领黄牌/红牌/询问某人是否出局,累计获得两张黄牌或者是得到过红牌就会出局。
分析:开一个数组cnt记录即可,黄牌+1, 红牌+2. 大于等于2的就要出局了。时间复杂度O ( q ) 

#include <iostream>
#include <algorithm>

using namespace std;

int n, q;


int main()
{
    cin >> n >> q;
    vector<int> red(n + 1, 0), yellow(n + 1, 0);
    
    
    while (q --)
    {
        int op, x;
        cin >> op >> x;
        
        if(op == 1) yellow[x] ++;
        if(op == 2) red[x] ++;
        
        if(op == 3)
        {
            if(yellow[x] >= 2 || red[x] >= 1)
            {
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
    }
    
    return 0;
}

Q3 Four Variables
题意:问四元组(A, B, C, D)满足AB + CD = n 的个数。
分析:先考虑简单的问题,如果问X + Y = n,求(X, Y)的数量,答案显然。然后再考虑怎么凑成X,就是X的因子对的数量,Y也是同理。设f [ x ] f[x]f[x]表示x的因子对数量,那么答案就是f [ 1 ] ∗ f [ n − 1 ] + f [ 2 ] ∗ f [ n − 2 ] + . . . + f [ n − 1 ] ∗ f [ 1 ] 。 f[1] * f[n - 1] + f[2] * f[n - 2] + ... + f[n - 1] * f[1]。f[1]∗f[n−1]+f[2]∗f[n−2]+...+f[n−1]∗f[1]。 时间复杂度O (n* 根号n) 

#include <iostream>
#include <vector>
#include <algorithm>

typedef long long LL;

using namespace std;

LL f(int x)
{
    LL res = 0;
    for (int i = 1; i * i <= x; i  ++)
    {
        if (x % i != 0)
            continue;
        int j = x / i;
        if (i == j)
            res++;
        else
            res += 2;
    }

    return res;
}

int main()
{
    int N;

    cin >> N;

    LL ans = 0;
    for (int x = 0; x < N; x ++)
    {
        ans += f(x) * f(N - x);
    }

    cout << ans << endl;

    return 0;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值