比赛地址
题目:[AcWing.4788 最大数量]
题型:
模拟
思路:
对于输入的小时 hh 和分钟 mm 只需将其都转化为分钟并用数组标记即可
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1000 + 5, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n;
int a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
int res = -1;
for (int i = 0; i < n; i ++)
{
int hh, mm;
cin >> hh >> mm;
a[hh * 60 + mm] ++;
res = max(res, a[hh * 60 + mm]); // 每次改变数组值时取max
}
cout << res << endl;
return 0;
}
题目:[AcWing.4789 前缀和序列]
题型:
前缀和
思路:
前缀和模板,注意要开 long long
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1e5 + 5, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, m;
int a[N], b[N];
LL aa[N], bb[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i ++) cin >> a[i], aa[i] = aa[i - 1] + a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i ++) b[i] = a[i], bb[i] = bb[i - 1] + b[i];
cin >> m;
while (m --)
{
int op, l, r;
cin >> op >> l >> r;
if (op == 1) cout << aa[r] - aa[l - 1] << endl;
else cout << bb[r] - bb[l - 1] << endl;
}
return 0;
}
题目:[AcWing.4790 买可乐]
题型:
模拟
思路:
枚举,
- 论箱买:最多买 m 箱就一定够,循环区间[0, m]
- 论瓶买:轮箱买后若还不够则论瓶买
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1e3 + 5, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int c, d, n, m, k;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> c >> d;
cin >> n >> m;
cin >> k;
if (k >= n * m) puts("0");
else
{
int res = INF;
for (int i = 0; i <= m; i ++) // 枚举箱数
{
int t = c * i;
if (k + n * i < n *m)
t += (n * m - n * i - k) * d;
res = min(res, t);
}
cout << res << endl;
}
return 0;
}