AtCoder ABC 249

A Jogging

没看清楚题 a不是移速 所以卡了十分钟 语法题

int main()
{
    int a, b, c, d, e, f, x;
    cin >> a >> b >> c >> d >> e >> f >> x; // 速度 b 和 e
    int aa1 = b * a, bb1 = e * d;
    
    int res1 = aa1 * (x / (a + c));
    int t = x % (a + c);
    if(t >= a)   res1 += aa1;
    else res1 += b * t;
    
    int res2 = bb1 * (x / (d + f));
    t = x % (d + f);
    if(t >= d)   res2 += bb1;
    else    res2 += e * t; 
    
    if(res1 > res2)
        puts("Takahashi");
    else if(res2 > res1)
        puts("Aoki");
    else
        puts("Draw");
    return 0;
}

B Perfect String

语法题 略

int main()
{
    map<int, int> mp;
    string s;
    cin >> s;
    bool ok = true;
    int n = s.size();
    rep(i, 0, n)
        mp[s[i] - 'a'] ++;
    for(auto x : mp)
        if(x.second > 1)
            ok = false;
 
    int da = 0, xiao = 0;
    rep(i, 0, n)
    {
        if(s[i] <= 'Z' && s[i] >= 'A')  da ++;
        if(s[i] <= 'z' && s[i] >= 'a')  xiao ++;
    }
    if(da == 0 || xiao == 0)  ok = false;
    if(ok)  puts("Yes");
    else puts("No");
}

C Just K(dfs)

任意选择的字符串 请问他们中的个数为k的字符 数量的最大值

简单搜索题 对于每一个字符串 可以选或者不选 dfs一下 注意代码实现

int n, k;

int dfs(vector<string> &a, vector<string> chosen, int idx)
{
    if(idx == a.size()) //当从所有字符串里选过之后
    {
        map<char, int> cnt;
        for(auto it : chosen) //加起来
        {
            rep(i, 0, (int)it.size())
                cnt[it[i]] ++;
        }
        int res = 0;
        for(auto it : cnt)
            if(it.second == k)   res ++;
        return res;
    }
 
    //搜索 要求最大值
    int a1 = dfs(a, chosen, idx + 1); //不选
    chosen.pb(a[idx]);
    int a2 = dfs(a, chosen, idx + 1); //选
    return max(a1, a2);
}

int main()
{
    cin >> n >> k;
    vector<string> a(n), b;
    rep(i, 0, n)
        cin >> a[i];
    
    cout << dfs(a, b, 0);
}

D Index Trio(排列组合)

给定数组A 取一个三元组**(i, j, k)** 要求满足a_i / a_j = a_k

这题被我读假了( 需要考虑到一种情况 a_i = 1 且 j = k

处理约数即可

eg 1 8 8
(1, 2, 2)
(1, 3, 3)
(1, 2, 3)
(1, 3, 2)
i的位置跟j颠倒 x2
== 8
(1, 1, 1) +1
res = 9
    由此可得核心代码
    rep(i, 0, n)
        cnt[a[i]] ++;
    
    LL res = 0;
    rep(i, 0, n)
    {
        for(int j = 1; j <= a[i] / j; j ++)
        {
            if(a[i] % j == 0)
            {
                res += 1LL * cnt[j] * cnt[a[i] / j];
                if(j * j != a[i])    
                    res += 1LL * cnt[j] * cnt[a[i] / j];
            }
        }
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值