重生之ACGO编程末世(第11~13集)
2026-05-03 05:48:24
发布于:浙江
好久没更新了,今天连更3集吧。
编程等级(从低到高):入门编程者、精英编程者、大师编程者、编程者王、编程者皇、编程之父(满10级进阶,需要吸收一道题目;刷题、参加竞赛可获得经验)
我的题技介绍:
第1题技:基础框架,可以直接生成1个基础框架(万能头+命名空间+主函数)
第2题技:函数掌控,可以根据题目生成出需要的变量、数组、函数
第3题技:核心开辟,可以知道30%任何题目的核心解题思路
续接上集:A39.[CSP-S 2019] 划分成功被我AC,我打坐盘膝,吸收A39.[CSP-S 2019] 划分,突破了编程者王(LV1),获得了第3题技·核心开辟,可以知道30%任何题目的核心解题思路。随后我又返回到平湖,等待A79553.模拟器的出没。
我突然改变了计划,召集了专攻难题团队(主团)里的所有核心成员(@LastKismet、@AC坤(100.00)(互关)、@请输入文本.、@暮雨朝云—月落、@互关而已、@༺ཌༀ༒AC王者༒ༀད༻),叫他们一起跟我一起去等待A79553.模拟器的出没,拼死一搏,狩猎A79553.模拟器。
很快,我们就来到了预先选好的躲藏点,没过一会儿,A79553.模拟器便出现了,它的出现引发了3级地震,大师编程者以下的基本活不过1分钟,我也是直接使用了 第1题技 + 第2题技 + 第3题技(功能看前置),知道了这道题目的核心思路是:不调用题目里给到的库,直接手写汇编。随后其他人分别使出自己的题技,已经构造好了20%算法部分,随后我们直接用:
#include <iostream>
#include <vector>
using namespace std;
int main() {
// 我们直接输出指令,不依赖库
// 初始化
cout << "S[2]=0;" << endl; // 用于临时存储
cout << "S[3]=0;" << endl; // 循环变量 i
cout << "S[4]=0;" << endl; // 循环变量 j
cout << "S[5]=0;" << endl; // 循环变量 k
cout << "S[6]=0;" << endl; // 临时存储返回值
cout << "S[7]=0;" << endl; // 累加和
// 读取 n1, n2, n3
cout << "ncall 1 S[0];" << endl; // 读 n1
cout << "ncall 1 S[1];" << endl; // 读 n2
cout << "ncall 1 S[2];" << endl; // 读 n3
// 保存到固定位置
cout << "S[100]=S[0];" << endl; // n1
cout << "S[101]=S[1];" << endl; // n2
cout << "S[102]=S[2];" << endl; // n3
// 读取 A 矩阵到内存 200 开始
cout << "S[8]=200;" << endl; // A 矩阵基址
cout << "S[3]=0;" << endl; // i=0
cout << "L1: if S[3]>=S[100] goto L2;" << endl;
cout << "S[4]=0;" << endl; // j=0
cout << "L3: if S[4]>=S[101] goto L4;" << endl;
cout << "ncall 1 M[S[8]];" << endl;
cout << "S[8]=S[8]+1;" << endl;
cout << "S[4]=S[4]+1;" << endl;
cout << "goto L3;" << endl;
cout << "L4: S[3]=S[3]+1;" << endl;
cout << "goto L1;" << endl;
cout << "L2:" << endl;
// 读取 B 矩阵到内存 50000 开始
cout << "S[8]=50000;" << endl; // B 矩阵基址
cout << "S[3]=0;" << endl; // j=0
cout << "L5: if S[3]>=S[101] goto L6;" << endl;
cout << "S[4]=0;" << endl; // k=0
cout << "L7: if S[4]>=S[102] goto L8;" << endl;
cout << "ncall 1 M[S[8]];" << endl;
cout << "S[8]=S[8]+1;" << endl;
cout << "S[4]=S[4]+1;" << endl;
cout << "goto L7;" << endl;
cout << "L8: S[3]=S[3]+1;" << endl;
cout << "goto L5;" << endl;
cout << "L6:" << endl;
// 初始化第五分块调用
// 先写 n, m
cout << "ncall 2 S[101];" << endl; // 写 n2
cout << "S[8]=S[101]*(1+S[102]+1);" << endl; // 计算 m
cout << "ncall 2 S[8];" << endl; // 写 m
// 写 x_j, y_j (都是 j+1)
cout << "S[3]=0;" << endl; // j=0
cout << "L9: if S[3]>=S[101] goto L10;" << endl;
cout << "S[8]=S[3]+1;" << endl;
cout << "ncall 2 S[8];" << endl; // x_j
cout << "ncall 2 S[8];" << endl; // y_j
cout << "S[3]=S[3]+1;" << endl;
cout << "goto L9;" << endl;
cout << "L10:" << endl;
// 主循环:对每个 i
cout << "S[3]=0;" << endl; // i=0
cout << "L11: if S[3]>=S[100] goto L20;" << endl;
// 设置 s_j = 1 对于 A[i][j] = 1
cout << "S[4]=0;" << endl; // j=0
cout << "L12: if S[4]>=S[101] goto L13;" << endl;
cout << "S[8]=200+S[3]*S[101]+S[4];" << endl; // A[i][j] 地址
cout << "if M[S[8]]==0 goto L14;" << endl; // 如果 A[i][j]==0 跳过
// 调用第五分块更新:a=1, b=0, c=-(j+1), v=1
cout << "ncall 2 1;" << endl; // a=1
cout << "ncall 2 0;" << endl; // b=0
cout << "S[8]=S[4]+1;" << endl;
cout << "S[8]=0-S[8];" << endl; // c=-(j+1)
cout << "ncall 2 S[8];" << endl;
cout << "ncall 2 1;" << endl; // v=1
cout << "ncall 1 S[6];" << endl; // 读返回值(丢弃)
cout << "L14: S[4]=S[4]+1;" << endl;
cout << "goto L12;" << endl;
cout << "L13:" << endl;
// 对每个 k 查询 C[i][k]
cout << "S[5]=0;" << endl; // k=0
cout << "L15: if S[5]>=S[102] goto L16;" << endl;
cout << "S[7]=0;" << endl; // sum=0
cout << "S[4]=0;" << endl; // j=0
cout << "L17: if S[4]>=S[101] goto L18;" << endl;
cout << "S[8]=50000+S[4]*S[102]+S[5];" << endl; // B[j][k] 地址
cout << "if M[S[8]]==0 goto L19;" << endl; // 如果 B[j][k]==0 跳过
// 调用第五分块更新:a=1, b=0, c=-(j+1), v=0
cout << "ncall 2 1;" << endl; // a=1
cout << "ncall 2 0;" << endl; // b=0
cout << "S[8]=S[4]+1;" << endl;
cout << "S[8]=0-S[8];" << endl; // c=-(j+1)
cout << "ncall 2 S[8];" << endl;
cout << "ncall 2 0;" << endl; // v=0
cout << "ncall 1 S[6];" << endl; // 读返回值
cout << "S[7]=S[7]+S[6];" << endl; // 累加
cout << "L19: S[4]=S[4]+1;" << endl;
cout << "goto L17;" << endl;
cout << "L18: ncall 2 S[7];" << endl; // 输出 C[i][k]
cout << "S[5]=S[5]+1;" << endl;
cout << "goto L15;" << endl;
cout << "L16:" << endl;
// 恢复 s_j = 0 对于 A[i][j] = 1
cout << "S[4]=0;" << endl; // j=0
cout << "L21: if S[4]>=S[101] goto L22;" << endl;
cout << "S[8]=200+S[3]*S[101]+S[4];" << endl; // A[i][j] 地址
cout << "if M[S[8]]==0 goto L23;" << endl; // 如果 A[i][j]==0 跳过
// 调用第五分块更新:a=1, b=0, c=-(j+1), v=-1
cout << "ncall 2 1;" << endl; // a=1
cout << "ncall 2 0;" << endl; // b=0
cout << "S[8]=S[4]+1;" << endl;
cout << "S[8]=0-S[8];" << endl; // c=-(j+1)
cout << "ncall 2 S[8];" << endl;
cout << "ncall 2 -1;" << endl; // v=-1
cout << "ncall 1 S[6];" << endl; // 读返回值(丢弃)
cout << "L23: S[4]=S[4]+1;" << endl;
cout << "goto L21;" << endl;
cout << "L22: S[3]=S[3]+1;" << endl;
cout << "goto L11;" << endl;
cout << "L20: exit;" << endl;
return 0;
}
在解题时间最后1秒成功AC。(千万别拿去试图AC现实中的,全WA,这里为了剧情推演,先这样)
爆出的东西:罐头×20000、超级函数库装备×1。
超级函数库:
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <cstdarg>
#include <immintrin.h>
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector", "fast-math")
#pragma GCC target("avx2", "avx512f", "avx512vl", "fma", "bmi2", "popcnt")
#pragma GCC diagnostic ignored "-Wunused-function"
typedef long long ll;
typedef double lf;
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define elif else if
#define swap_d(a, b) do { ll _t = (a); (a) = (b); (b) = _t; } while(0)
#define swap_f(a, b) do { lf _t = (a); (a) = (b); (b) = _t; } while(0)
#define swap_c(a, b) do { char _t = (a); (a) = (b); (b) = _t; } while(0)
#define memcpy(r1, s, len) __builtin_memcpy((r1), (s), (len))
#define strlen(r1) __builtin_strlen((r1))
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n))
static const lf pi = 3.14159265358979323846;
static const lf e = 2.71828182845904523536;
static char _rbuf[1 << 16];
static char* _rptr = _rbuf;
static char* _rend = _rbuf;
// 获取下一个字符(带缓冲)
static inline char _gc() {
if (unlikely(_rptr == _rend)) { // 缓冲区耗尽是小概率事件
_rend = _rbuf + fread(_rbuf, 1, sizeof(_rbuf), stdin);
_rptr = _rbuf;
if (unlikely(_rptr == _rend)) return EOF; // 文件结束是极小概率事件
}
return *_rptr++;
}
static char _wbuf[1 << 16];
static char* _wptr = _wbuf;
// 输出单个字符(带缓冲)
static inline void _pc(char c) {
if (unlikely(_wptr == _wbuf + sizeof(_wbuf))) { // 缓冲区满是小概率事件
fwrite(_wbuf, 1, sizeof(_wbuf), stdout);
_wptr = _wbuf;
}
*_wptr++ = c;
}
// 刷新输出缓冲区
static inline void _return() {
if (likely(_wptr != _wbuf)) { // 通常为 True
fwrite(_wbuf, 1, _wptr - _wbuf, stdout);
_wptr = _wbuf;
}
}
namespace std{
struct string {
char r1[1001];
// 初始化空字符串
string() { r1[0] = '\0'; }
// 初始化为单字符
string(char c) { r1[0] = c; r1[1] = '\0'; }
// 从C字符串构造
string(const char* s) {
if (unlikely(!s)) { r1[0] = '\0'; return; }
size_t len = strlen(s);
if (len > 1000) len = 1000;
memcpy(r1, s, len);
r1[len] = '\0';
}
// 拷贝构造函数
string(const string& other) {
size_t len = strlen(other.r1);
if (len > 1000) len = 1000;
memcpy(r1, other.r1, len);
r1[len] = '\0';
}
// 赋值操作符重载
string& operator=(const string& other) {
if (this != &other) {
size_t len = strlen(other.r1);
if (len > 1000) len = 1000;
memcpy(r1, other.r1, len);
r1[len] = '\0';
}
return *this;
}
// 下标访问操作符重载(可写)
inline char& operator[](int i) { return r1[i]; }
// 下标访问操作符重载(只读)
inline const char& operator[](int i) const { return r1[i]; }
// 字符串相等判断操作符重载
bool operator==(const string& other) const {
size_t l1 = strlen(r1);
size_t l2 = strlen(other.r1);
if (l1 != l2) return false;
return memcmp(r1, other.r1, l1) == 0;
}
// 字符串不等判断操作符重载
bool operator!=(const string& other) const { return !(*this == other); }
// 字符串拼接操作符重载(返回新字符串)
string operator+(const string& other) const {
string res;
size_t l1 = strlen(r1);
size_t l2 = strlen(other.r1);
size_t total = l1 + l2;
if (total > 1000) total = 1000;
if (l1 > 0) memcpy(res.r1, r1, l1);
if (total > l1 && l2 > 0) {
size_t copy_len = (total - l1 < l2) ? (total - l1) : l2;
memcpy(res.r1 + l1, other.r1, copy_len);
}
res.r1[total] = '\0';
return res;
}
// 原地拼接字符串操作符重载(string)
string& operator+=(const string& other) {
size_t l1 = strlen(r1);
size_t l2 = strlen(other.r1);
if (l1 + l2 >= 1000) {
size_t space = 1000 - l1;
if (space > 0) memcpy(r1 + l1, other.r1, space);
r1[1000] = '\0';
} else {
memcpy(r1 + l1, other.r1, l2);
r1[l1 + l2] = '\0';
}
return *this;
}
// 原地拼接C字符串操作符重载
string& operator+=(const char* s) {
size_t l1 = strlen(r1);
size_t l2 = strlen(s);
if (l1 + l2 >= 1000) {
size_t space = 1000 - l1;
if (space > 0) memcpy(r1 + l1, s, space);
r1[1000] = '\0';
} else {
memcpy(r1 + l1, s, l2);
r1[l1 + l2] = '\0';
}
return *this;
}
// 原地拼接字符操作符重载
string& operator+=(char c) {
size_t len = strlen(r1);
if (likely(len < 1000)) {
r1[len] = c;
r1[len + 1] = '\0';
}
return *this;
}
// 获取字符串长度
inline int size() const { return (int)strlen(r1); }
// 判断字符串是否为空
inline bool empty() const { return r1[0] == '\0'; }
// 获取C风格字符串指针
inline const char* c_str() const { return r1; }
// 清空字符串
inline void clear() { r1[0] = '\0'; }
// 尾部追加字符
inline void push_back(char c) {
size_t len = strlen(r1);
if (likely(len < 1000)) {
r1[len] = c;
r1[len + 1] = '\0';
}
}
// 获取子串
string substr(int pos, int len = -1) const {
string res;
int sz = (int)strlen(r1);
if (pos < 0) pos = 0;
if (pos >= sz) return res;
if (len < 0 || pos + len > sz) len = sz - pos;
memcpy(res.r1, r1 + pos, (size_t)len);
res.r1[len] = '\0';
return res;
}
// 查找子串位置
int find(const string& sub) const {
if (sub.empty()) return 0;
const char* p = strstr(r1, sub.r1);
return p ? (int)(p - r1) : -1;
}
};
// C字符串 + 自定义字符串
inline string operator+(const char* s, const string& str) {
string res(s);
res += str;
return res;
}
// 字符 + 自定义字符串
inline string operator+(char c, const string& str) {
string res(c);
res += str;
return res;
}
// 字符串快读 (跳过空白)
inline string read_s() {
string a;
char c = _gc();
while (c <= 32) {
if (c == EOF) return a;
c = _gc();
}
int cnt = 0;
while (c > 32 && cnt < 1000) {
a.r1[cnt++] = c;
c = _gc();
}
a.r1[cnt] = '\0';
return a;
}
// 读取整行 (不含换行符)
inline void getline(string& s) {
char c = _gc();
int cnt = 0;
while (cnt < 1000) {
if (c == '\n' || c == '\r' || c == EOF) break;
s.r1[cnt++] = c;
c = _gc();
}
s.r1[cnt] = '\0';
}
// 字符串快写
inline void write_s(const string& a) {
const char* p = a.r1;
while (*p) _pc(*p++);
}
// 字符串反转
inline void reverse(string& s) {
int len = s.size();
int half = len >> 1;
char* start = s.r1;
char* end = s.r1 + len - 1;
for (int i = 0; i < half; ++i) {
swap_c(*start, *end);
start++;
end--;
}
}
}; // string 类型 字符串(带输出输入工具)
using namespace std;
namespace Code{
// 整数快读 (ll)
inline ll read_d() {
ll x = 0;
int f = 1;
char c = _gc();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = _gc();
if (unlikely(c == EOF)) break;
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = _gc();
}
return f == 1 ? x : -x;
}
// 浮点快读 (lf)
inline lf read_f() {
ll ip = 0;
lf f = 1.00;
char c = _gc();
// 1. 跳过前导空白和符号
while (c < '0' || c > '9') {
if (c == '-') f = -1.00;
c = _gc();
if (unlikely(c == EOF)) break;
}
// 2. 读取整数部分
while (c >= '0' && c <= '9') {
ip = (ip << 3) + (ip << 1) + (c ^ 48);
c = _gc(); // 此时 c 已经是小数点或者分隔符(如空格)
}
lf fp = 0.00, base = 0.1;
// 3. 直接使用刚才读到的 c 进行判断,不要重新 _gc()
if (c == '.') {
c = _gc(); // 只有确认是小数点后,才读取下一位小数
while (c >= '0' && c <= '9') {
fp += (c ^ 48) * base;
base *= 0.1;
c = _gc();
}
}
return double(ip + fp) * f;
}
inline void read_w(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
char c;
while (*fmt) {
if (*fmt == '%') {
fmt++;
if (!*fmt) break;
if (*fmt == 's') {
string* s = va_arg(args, string*);
s -> clear();
c = _gc();
while (c <= 32) { if (c == EOF) goto end; c = _gc(); }
while (c > 32) {
s->push_back(c);
c = _gc();
if(c == EOF) break;
}
}
else if (*fmt == 'd') {
ll* val = va_arg(args, ll*);
*val = read_d();
}
else if (*fmt == 'c') {
char* val = va_arg(args, char*);
*val = _gc();
}
else if (*fmt == 'l') {
if (*(fmt+1) == 'f') {
fmt++;
lf* val = va_arg(args, lf*);
*val = read_f();
}
}
else if (*fmt == 'f') {
lf temp = read_f();
float* val = va_arg(args, float*);
*val = (float)temp;
}
} else {
c = _gc();
while (c <= 32 && *fmt != '%') c = _gc();
}
fmt++;
}
end:
va_end(args);
}
// 整数快写 (ll)
void write_d(ll x) {
if (x == 0) { _pc('0'); return; }
if (x < 0) { _pc('-'); x = -x; }
char buf[25];
char* ptr = buf + 24;
*ptr = '\0';
while (x > 0) {
*--ptr = '0' + (char)(x % 10);
x /= 10;
}
while (*ptr) _pc(*ptr++);
}
// 浮点快写 (指定位数)
inline void write_p(lf x, int max_decimal) {
if (x == 0.0) { _pc('0'); return; }
if (x < 0) { _pc('-'); x = -x; }
ll int_part = (ll)x;
write_d(int_part);
if (max_decimal <= 0) return;
_pc('.');
lf frac_part = x - (lf)int_part;
for (int i = 0; i < max_decimal; i++) {
frac_part *= 10.0;
ll digit = (ll)frac_part;
_pc('0' + (char)digit);
frac_part -= (lf)digit;
}
}
// 浮点快写 (默认15位精度)
inline void write_f(lf x) { write_p(x, 15); }
// 格式化输出 (类似printf)
void write_w(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
while (*fmt) {
if (*fmt == '%') {
fmt++;
if (!*fmt) break;
ll precision = -1;
if (*fmt == '.' && *(fmt+1) == '*') {
fmt += 2;
precision = va_arg(args, ll);
}
else if (*fmt == '.') {
fmt++;
ll p = 0;
bool has_digit = false;
while(*fmt >= '0' && *fmt <= '9') {
p = p * 10 + (*fmt - '0');
fmt++;
has_digit = true;
}
if (has_digit) precision = p;
}
switch (*fmt) {
case 'd':
case 'i':
write_d((ll)va_arg(args, ll));
break;
case 'l':
if (*(fmt+1) == 'd') {
write_d(va_arg(args, ll));
fmt++;
} else {
write_d((ll)va_arg(args, ll));
}
break;
case 'L':
if (*(fmt+1) == 'd') {
write_d(va_arg(args, ll));
fmt++;
}
break;
case 'f':
case 'F':
case 'g':
case 'G':
if (precision >= 0) {
write_p(va_arg(args, lf), precision);
} else {
write_f(va_arg(args, lf));
}
break;
case 's': {
const char* s = va_arg(args, const char*);
write_s(s);
break;
}
case 'c':
_pc((char)va_arg(args, int));
break;
case '%':
_pc('%');
break;
default:
_pc('%');
_pc(*fmt);
break;
}
} else if (*fmt == '\\') {
fmt++;
if (!*fmt) break;
switch (*fmt) {
case 'n': _pc('\n'); break;
case 't': _pc('\t'); break;
case 'r': _pc('\r'); break;
case '\\': _pc('\\'); break;
case '"': _pc('"'); break;
default:
_pc('\\');
_pc(*fmt);
break;
}
} else {
_pc(*fmt);
}
fmt++;
}
va_end(args);
}
};
using namespace Code; // C语言输出输入工具
namespace math{
// 整数数组求和
ll sum_d(ll a[], int n) {
ll sum = 0;
for (int i = 0; i < n; ++i) sum += a[i];
return sum;
}
// 浮点数组求和
lf sum_f(lf a[], int n) {
lf sum = 0;
for (int i = 0; i < n; ++i) sum += a[i];
return sum;
}
// 浮点乘方 (优化)
lf pow(lf a, lf b) {
ll ll_b = (ll)b;
lf lf_b = b - ll_b;
if (lf_b != 0.00) return __builtin_pow(a, b);
if (a == 1.0 || ll_b == 0) return 1.0;
if (a == 0.0) return 0.0;
if (a == -1.0) return (ll_b & 1) ? -1.0 : 1.0;
bool neg = false;
if (ll_b < 0) {
neg = true;
ll_b = -ll_b;
}
lf res = 1.0;
lf base = a;
while (ll_b > 0) {
if (ll_b & 1) res *= base;
base *= base;
ll_b >>= 1;
}
return neg ? 1.0 / res : res;
}
lf sqrt(lf x, lf n) {if (unlikely(n == 0 || x == 0)) return 0;
if (unlikely(n == 1)) return x;
if (likely(n == 2)) return __builtin_sqrt(x);
if (unlikely(x < 0 && static_cast<long long>(n) % 2 == 0)) {
return 0.0L / 0.0L;
}
// 3. 牛顿迭代法
long double y = x; // 初始猜测值,可以设为 x 或 1.0
long double prev_y;
const long double epsilon = 1e-15L; // 精度控制,当两次迭代结果差值小于此值时停止
do {
prev_y = y;
long double y_power_n_minus_1 = 1.0L;
for (int i = 0; i < static_cast<int>(n) - 1; ++i) {
y_power_n_minus_1 *= prev_y;
}
y = ((n - 1) * prev_y + x / y_power_n_minus_1) / n;
} while (y > prev_y ? y - prev_y > epsilon : prev_y - y > epsilon);
return y;
}
// 最大公约数
inline ll gcd(ll a, ll b) {
while (b) {
a %= b;
swap_d(a, b);
}
return a;
}
// 最小公倍数
inline ll lcm(ll a, ll b) {
if (a == 0 || b == 0) return 0;
return (a / gcd(a, b)) * b;
}
}; // 数学函数库
using namespace math;
// 自定义区域
// 主函数入口
int main() {
_return();
}
我们商量好了,我要罐头×3500、超级函数库装备×1,剩余的他们自己分。
随后,我去了中国电子计算机学会商店,买了一个ACGO鼠标垫,使我解题速度变快30%。
未完待续……
全部评论 3
可以啊
4天前 来自 浙江
0。
5天前 来自 上海
0厉害
5天前 来自 上海
0包的
5天前 来自 浙江
0

























有帮助,赞一个