Codeforces Round #523 (Div. 2)

A

简单题

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n, m, ans;
    cin >> n >> m;
    ans = m / n;
    if(m % n != 0)ans++;
    cout << ans << endl;
    return 0;
}

B

开始以为可以贴着边放置,其他的去掉,第五个样例没过,重新想,发现在原想法基础上可以一个块放在高处代替两个块,看到只有2e5就开数组了,结果re7,返回去看题发现m范围是1e9,于是把数组改成map,提交mle10,又想了想,发现不需要map,定义一个游动变量就可以了。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
//map<ll, ll>vis;
int main()
{
    ll n, m, i, j, k, sum = 0, maxx = -1;
    scanf("%lld %lld", &n, &m);
    for(i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
        sum += a[i];
        maxx = max(maxx, a[i]);
    }
    sort(a + 1, a + 1 + n);
    ll ans = 0;
    ll p = maxx;
    ll num = 0;
    for(i = n; i >= 1; i--)
    {
        ans++;
        if(p == 0)continue;
        if(a[i] >= p)
        {
            p--;
            num++;
        }
        else
        {
            p = a[i];
            num++;
            p--;
        }
    }
//    cout << n << endl;
//    cout << num << endl;
    ans += max((ll)0, maxx - num);
    printf("%lld\n", sum - ans);

    return 0;
}

赛后补题:

C

dp题,比较像背包,当时没敢往这方面想,觉得会超时,但事实不会超时。。。

发现一篇讲的很好的博客,直接贴过来吧。。

https://blog.csdn.net/godleaf/article/details/84402128

附上自己补的代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll a[100005], dp[100005] = {0};
vector<ll>num[100005];
void getnum(ll x)
{
    stack<ll>st;
    ll tmp = a[x], i;
    for(i = 1; i * i <= tmp; i++)
    {
        if(tmp % i != 0)continue;
        num[x].push_back(i);
        if(tmp != i * i)
        {
            st.push(tmp / i);
        }
    }
    while(st.empty() == 0)
    {
        num[x].push_back(st.top());
        st.pop();
    }
    return ;
}
int main()
{
    ll n, m, i, j, k;
    scanf("%lld", &n);
    for(i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
        getnum(i);
    }
    dp[0] = 1;
    for(i = 1; i <= n; i++)
    {
        ll len = num[i].size();
        for(j = len - 1; j >= 0; j--)
        {
            ll tmp = num[i][j];
            if(tmp <= n && tmp - 1 >= 0)
            {
                dp[tmp] = (dp[tmp] + dp[tmp - 1]) % MOD;
            }
        }
    }
    ll ans = 0;
    for(i = 1; i <= n; i++)
    {
        ans += dp[i];
        ans %= MOD;
    }
    printf("%lld\n", ans);
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值