跳到正文

个人记录

8.4综合测试总结

#SUSPENDED#约 16 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月23日
篇幅
约 16 分钟

版本

  1. v1当前

B4073 [CSP-X 2018] 快递费用

题目描述

某快递公司按邮寄物品的重量收费,收费标准如下:

重量在 500500 克以内的,一律 2020 元;

超过 500500 克的,超重的部分按每 500500 克加收费用。超出的重量不足 500500 克的,按 500500 克计算。例如:10201020 克,超重 520520 克,需加收两份费用。

根据目的地的不同,加收的费用是不一样的。快递公司划分了五个目的地区域:

  • 区域 11:每超重 500500 克加收 44 元;

  • 区域 22:每超重 500500 克加收 66 元;

  • 区域 33:每超重 500500 克加收 99 元;

  • 区域 44:每超重 500500 克加收 1010 元;

  • 区域 55:每超重 500500 克加收 1717 元。

给出物品的重量 ww 和目的地区域编号 nn,请你计算快递费用。

正确代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dx[] = {0, 4, 6, 9, 10, 17};
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int w, n;
	cin >> w >> n;
	if (w <= 500) cout << 20 << endl;
	else {
		int s = (w - 500) / 500;
		if ((w - 500) % 500 != 0) s++;
		cout << 20 + dx[n] * s;
	}
	return 0;
}

T638889 石头布没有剪刀

题目描述

你和对手都只有两种出拳方式:石头(gg)和布(pp),规则一样,赢了得一分,平局不得分,输了减一分。 现给你对手的出拳方式,设你到 ii 位置共出了 xix_i 次石头,yiy_i 次布,在对于任意位置 ii 满足 xi≥yix_i \geq y_i 的条件下,输出你能得到的最大分数。

输入格式

一个字符串 ss 只包含 gg 和 pp 两种字符串。

输出格式

输出能得到的最大分数。

正确代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> s;
	int cnt = 0, len = s.size();
	for (int i = 0; i < len; i++)
		if (s[i] == 'p') cnt++;
	int x = len / 2;
	cout << x - cnt;
	return 0;
}

T644252 篝火问题

题目描述

在无限广阔的二维网格中,坐标 (0,0)(0, 0) 处有一堆篝火。 在时刻 t=0t=0 时,仅单元格 (0,0)(0, 0) 存在烟雾。

给定一个由 N、W、S、E 组成且长度为 NN 的字符串 SS,在时刻 t=1,2,…,Nt=1,2,\dots,N 时,将按顺序发生以下现象:

  • 风吹过时,当前存在的所有烟雾将按以下规则移动:
    • 若 SS 的第 tt 个字符为 N,则单元格 (r,c)(r, c) 的烟雾移动到 (r−1,c)(r-1, c)。
    • 若 SS 的第 tt 个字符为 W,则单元格 (r,c)(r, c) 的烟雾移动到 (r,c−1)(r, c-1)。
    • 若 SS 的第 tt 个字符为 S,则单元格 (r,c)(r, c) 的烟雾移动到 (r+1,c)(r+1, c)。
    • 若 SS 的第 tt 个字符为 E,则单元格 (r,c)(r, c) 的烟雾移动到 (r,c+1)(r, c+1)。
  • 若此时单元格 (0,0)(0, 0) 没有烟雾,则在该位置生成新的烟雾。

落落的去位于坐标 (R,C)(R, C) 处。 对于每个整数 1≤t≤N1 \leq t \leq N,请判断在时刻 t+0.5t+0.5 时单元格 (R,C)(R, C) 是否存在烟雾,并按输出格式要求输出结果。

输入格式

第一行输入三个整数 N,R,CN,R,C。
第二行是一行带方向的字符串 SS。

输出格式

将答案作为由 NN 个 0 和 1 组成的字符串输出。 输出字符串的第 tt 个字符 (1≤t≤N1 \leq t \leq N) 应满足以下规则:

  • 若时刻 t+0.5t+0.5 时单元格 (R,C)(R, C) 存在烟雾,则为 1
  • 若时刻 t+0.5t+0.5 时单元格 (R,C)(R, C) 不存在烟雾,则为 0

输入输出样例 #1

输入 #1

代码
6 -2 1
NNEEWS

输出 #1

代码
001010

输入输出样例 #2

输入 #2

代码
10 1 2
NEESESWEES

输出 #2

代码
0001101011

输入输出样例 #3

输入 #3

代码
20 -1 -2
WWNNWSWEWNSWWENSNWWN

输出 #3

代码
00100111111000101111

说明/提示

对于 3030% 的测试点: 1≤N≤1000,R,C≤∣10∣1\leq N\leq 1000,R,C \leq |10|。
对于所有测试点:1≤N≤2∗1051\leq N \leq 2*10^{5},R,C≤∣2∗105∣,(R,C)≠(0,0)R,C \leq |2*10^5|,(R,C) \neq (0,0)。

样例解释 1

在时刻 1.51.5、2.52.5、4.54.5、6.56.5 时,单元格 (−2,1)(-2, 1) 不存在烟雾;在时刻 3.53.5、5.55.5 时存在烟雾。因此输出 001010。 图示中以篝火所在的单元格 (0,0)(0, 0) 为基准:

  • 若 r<0r < 0,则单元格 (r,c)(r, c) 位于上方 ∣r∣|r| 格
  • 若 r≥0r \geq 0,则单元格 (r,c)(r, c) 位于下方 rr 格
  • 若 c<0c < 0,则单元格 (r,c)(r, c) 位于左侧 ∣c∣|c| 格
  • 若 c≥0c \geq 0,则单元格 (r,c)(r, c) 位于右侧 cc 格

各时刻的网格状态如下:

  • 时刻 0.50.5:
  • 时刻 1.51.5:
  • 时刻 2.52.5:
  • 时刻 3.53.5:
  • 时刻 4.54.5:
  • 时刻 5.55.5:
  • 时刻 6.56.5:

错误代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 2e5;
int n, r, c;
string s;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> r >> c >> s;
	int x = r, y = c, len = s.size();
	for (int i = 0; i < len; i++) {
		if (s[i] == 'N') x++;
		else if (s[i] == 'W') y++;
		else if (s[i] == 'S') x--;
		else if (s[i] == 'E') y--;
		if (x == 0 && y == 0) cout << 1;
		else cout << 0;
	}
	return 0;
}

错误原因

思路错误

正确思路

  • 我们可以想到如果直接处理烟雾, 会非常麻烦
  • 我们可以考虑一定人和篝火
  • 我们只要篝火移动的路径, 如果人走到了篝火走过的地方, 就输出11, 否则输出00
  • 我们可以用一个二维mapmap记录篝火走过的地方。 定义方法:map<int, map<int, bool> > mp;或map<pair<int, int>, bool> mp;
  • 伪代码如下:
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, r, c;//r, c表示人的位置
string s;
map<int, map<int, bool> > mp;//用做标记
signed main() {
	//输入
	int x = 0, y = 0;//篝火位置
	//标记篝火的位置, mp[0][0] = true;
	for () {
		//如果是N, 人和篝火都往下走, 行号 + 1
		//如果是W, 人和篝火都往右走, 列号 + 1
		//如果是S, 人和篝火都往上走, 行号 - 1
		//如果是E, 人和篝火都往左走, 列号 - 1
		//标记
		//输出
	}
	return 0;
}

正确代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 2e5;
int n, r, c;
string s;
map<int, map<int, bool> > mp;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> r >> c >> s;
	int x = 0, y = 0, len = s.size();
	mp[0][0] = true;
	for (int i = 0; i < len; i++) {
		if (s[i] == 'N') x++, r++;
		else if (s[i] == 'W') y++, c++;
		else if (s[i] == 'S') x--, r--;
		else if (s[i] == 'E') y--, c--;
		mp[x][y] = true;
		cout << mp[r][c];
	}
	return 0;
}

T639146 落落的去的数学问题3

题目描述

对于正整数 x,yx, y,定义 f(x,y)f(x, y) 如下:

  • 将 x,yx, y 的十进制表示分别作为字符串解释,并按顺序连接,得到字符串 zz。将 zz 作为十进制整数解释,其值即为 f(x,y)f(x, y)。

例如,f(3,14)=314f(3,14)=314,f(100,1)=1001f(100,1)=1001。

给定一个长度为 NN 的正整数序列 A=(A1,…,AN)A=(A_1,\ldots,A_N)。请计算下式的值对 998244353998244353 取模的结果:

∑i=1N−1∑j=i+1Nf(Ai,Aj)\sum_{i=1}^{N-1}\sum_{j=i+1}^N f(A_i,A_j)

错误代码

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int m[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000};
int a[1000007], ans, sum, cnt;
signed main() {
	ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
   	for (int i = 1; i < n; i++)
   		for (int j = i + 1; j <= n; j++) {
   			int x = a[j], s = 0;
   			while (x) {x /= 10; s++;}
			ans += (a[i] * m[s] + a[j]) % mod;
		}
	cout << ans % mod;
	return 0;
}

错误原因

思路错误∗2 * 2

正确思路

  • 首先我先介绍一些函数:
  1. to_string, 他的作用是把数字变成字符串

    举例 : string sn = to_string (356345);

  2. .size(), 他的作用是求出数字的位数

    举例 : int len = sn.size()

  3. stoi, 他的作用是把字符串变成intint类型

    举例 : int x = stoi ("423423");

  4. atoll, 他的作用是把字符串变成longlong longlong类型

    举例 : long long y = stoll("323423");

    这些函数的复杂度都是O(n)O(n)

  • 我们可以很轻松想出暴力解, 代码如下:
C++
for (int i = 1; i <= n; i++) {
	for (int j = i + 1; j <= n; j++) {
		ll x = stoll(to_string(a[i]) + to_string(a[j]));
		ans = (ans % mod + x % mod) % mod;
	}
}
cout << ans % mod;
  • 我们可以得到一个结论:f(ai,aj)=ai∗10的aj次方+ajf(a_i, a_j) = a_i * 10的a_j次方 + a_j

  • 对应每个aia_i, (a[1]+a[2]+a[3]+...+a[j−1])∗10的a[j]次方+(j−1)∗a[j](a[1] + a[2] + a[3] + ... + a[j - 1]) * 10的a[j]次方 + (j - 1) *a[j]

  • 核心代码如下:

C++
for (int j = 1; j <= n; j++) {
   	int len = to_string(a[j]).size();
	ans += (((a[1] + a[2] + ...... + a[j - 1]) * (long(pow(10, len)) % mod)) % mod + ((j - 1) * a[j]) % mod) % mod;
}

正确代码

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int m[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000};
int a[1000007], ans, cnt;
int sum[10000007];
signed main() {
	ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum[i] = (sum[i - 1] + a[i]) % mod;
	}
   	for (int j = 1; j <= n; j++) {
   		int len = to_string(a[j]).size();
		ans += ((sum[j - 1] * (long(pow(10, len)) % mod)) % mod + ((j - 1) * a[j]) % mod) % mod;
	}
	cout << ans % mod;
	return 0;
}

P1100 高低位交换

题目描述

给出一个小于 2322^{32} 的非负整数。这个数可以用一个 3232 位的二进制数表示(不足 3232 位用 00 补足)。我们称这个二进制数的前 1616 位为“高位”,后 1616 位为“低位”。将它的高低位交换,我们可以得到一个新的数。试问这个新的数是多少(用十进制表示)。

例如,数 13145201314520 用二进制表示为 0000 0000 0001 0100 0000 1110 1101 10000000\,0000\,0001\,0100\,0000\,1110\,1101\,1000(添加了 1111 个前导 00 补足为 3232 位),其中前 1616 位为高位,即 0000 0000 0001 01000000\,0000\,0001\,0100;后 1616 位为低位,即 0000 1110 1101 10000000\,1110\,1101\,1000。将它的高低位进行交换,我们得到了一个新的二进制数 0000 1110 1101 1000 0000 0000 0001 01000000\,1110\,1101\,1000\,0000\,0000\,0001\,0100。它即是十进制的 249036820249036820。

正确代码

C++
#include<bits/stdc++.h>
using namespace std;
int main() {
	unsigned int n;
	cin >> n;
	cout << (n >> 16) + (n << 16);
	return 0;
}
原文