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