天梯选拔赛补题

A - My Friend of Misery

如果支付失败,那么最大值=之前支付成功的+这次想支付但失败的+25-1。
如果支付成功,那么最小值=之前所有支付成功的。

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long long n, num;
        char s[3];
        scanf("%lld", &n);
        long long l = 0, r = 10000000000000000, ans = 10000000000000000;
        for (int i = 1; i <= n; i++)
        {
            scanf("%lld%s", &num, s);
            if (s[0] == '-')
            {
                r = min(r, l + num + 25);
                // r = l + num + 25;//不取min WA了,感觉是有不合法数据
            }
            else
            {
                l += num + 25;
            }
            ans = min(ans, r - l);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

F - Chance

比赛时读错题了, the number that have a prime number of ones in their binary representation. 翻译成了一种二进制表示时是质数的数,应该是二进制表示中一的数量是质数的数…

AC代码:

int get(int x)
{
    int res = 0;
    while (x)
    {
        if (x % 2)
            res++;
        x /= 2;
    }
    return res;
}
int f(int x)
{
    if (x == 0 || x == 1)
        return 0;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
            return 0;
    return 1;
}
int ans[100010];
inline void pre()
{
    for (int i = 1; i <= 100000; i++)
        ans[i] = f(get(i)) ? ans[i - 1] + 1 : ans[i - 1];
}
int main()
{
    pre();
    int t;
    cin >> t;
    while (t--)
    {
        int l, r;
        cin >> l >> r;
        cout << ans[r] - ans[l - 1] << endl;
    }
    return 0;
}

ACPC Headquarters : AASTMT (Stairway to Heaven)

map set 搞一搞,加各种标记优化~

struct node
{
    int L, R;
    map<string, int> mp;
} comp[110];
inline bool f(int l1, int r1, int l2, int r2)
{
    if (l1 == l2 || l1 == r2 || r1 == l2 || r1 == r2)
        return 1;
    if (l1 > l2 && l1 < r2)
        return 1;
    if (r1 > l2 && r1 < r2)
        return 1;
    if (l1 < l2 && r1 > r2)
        return 1;
    return 0;
}
set<string> ans;
set<string> vis;
char s[100];
int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n, l, r, m;
        scanf("%d", &n);
        ans.clear();
        vis.clear();
        for (int i = 1; i <= n; i++)
        {
            comp[i].mp.clear();
            scanf("%s%d%d%d", s, &comp[i].L, &comp[i].R, &m);
            for (int j = 1; j <= m; j++)
            {
                scanf("%s", s);
                comp[i].mp[s] = 1;
            }
            for (auto it = comp[i].mp.begin(); it != comp[i].mp.end(); it++)
            {
                if (ans.count(it->first) || !vis.count(it->first))
                    continue;
                for (int j = 1; j < i; j++)
                {
                    if (f(comp[i].L, comp[i].R, comp[j].L, comp[j].R))
                    {
                        for (auto it2 = comp[j].mp.begin(); it2 != comp[j].mp.end(); it2++)
                        {
                            if (it->first == it2->first)
                            {
                                ans.insert(it2->first);
                            }
                        }
                    }
                }
            }
            for (auto it = comp[i].mp.begin(); it != comp[i].mp.end(); it++)
                vis.insert(it->first);
        }
        printf("%d\n", ans.size());
        for (auto it = ans.begin(); it != ans.end(); it++)
            printf("%s\n", (*it).c_str());
    }
    return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hesorchen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值