跳到正文

题解

题解:P10862 [HBCPC2024] Spicy or Grilled?

wuyi2026约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月4日
篇幅
约 3 分钟
获赞
2
题目
P10832

版本

  1. v1当前

题目传送门 这道题很水,我都后悔没报这场比赛。


题目大意就是一共 aa 个选手吃汉堡,有 bb 个不吃辣,吃 dd 元钱的不辣堡,剩下的选手都吃辣的汉堡,最后要花多少。

分析一下:bb 个不吃辣,就是 b×db \times d, 剩下的选手即 (a−b)×c(a-b) \times c 元钱的汉堡,便可以使用快读加手写队列得出答案,先计算公式: (a−b)×c+b×d(a-b)\times c+b\times d,在代码中有很大用处。


AC代码:

C++
#include<bits/stdc++.h> //万能头
using namespace std;
typedef long long ll;
inline ll /*防止数读进来超int*/ read() {
	ll n = 0;
	int f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		n = (n << 3) + (n << 1) + (c ^ 48);
		c = getchar();
	}
	return n * f;
}//快读模板
inline void write(ll x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9) write(x / 10);
	putchar((x % 10) ^ 48);
	return;
}//快写模板
//结构体,
struct node {
	ll a[5];//四个变量
} f[100005];
node q[100005];//手写队列
ll tt, hh;
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		f[i].a[0] = read(), f[i].a[1] = read(), f[i].a[2] = read(), f[i].a[3] = read();//读入
		f[i].a[4] = (f[i].a[0] - f[i].a[1]) * f[i].a[2] + f[i].a[1] * f[i].a[3];//计算买汉堡的钱
		q[hh ++] = f[i];//计入队列
	}
	while (tt <= hh - 1) {//输出队列元素
		write(q[tt ++].a[4]);//快写输出+弹出元素
		puts("");//换行
	}
	return 0;
}

AC记录

原文