Acwing 第 84 场周赛

比赛地址

题目:[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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值