跳到正文

题解

a+b problem · 《简单写法》

Zhenggeek约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
获赞
1
题目
P1001

版本

  1. v1当前

众所周知

a+b problem是大部分oier/acmer写完hello world之后的第一个程序,那当我们达到一定水平后一定会想着用多一点的方法来解题,有人用上了高级算法,有人用上了高级的数据结构,有人还是用朴实无华的方式。而我选择使用一个比赛时常常会使用的技巧——快读快写!!!(把字刻在石头上!!!

首先,我们要了解一下快读快写的原理:手动解析数据,并使用位运算进行加速。

那接下来就是代码:

C++
#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;

template<typename T>
bool read(T &x){
	x = 0;T f = 1;
	char ch = getchar();
	if(ch == EOF) return false;
	while(!isdigit(ch)){
		if(ch == '-') f = -1;
		ch = getchar();
		if(ch == EOF) return false;
	}while(isdigit(ch)){
		x = x*10 + (ch ^ 48);
		ch = getchar();
	}x*=f;
	return true;
}
template<typename T>
inline void write(T x){
	if(x<0){
		putchar('-');
		x = -x;
	}static char buf[40];
	int len = 0;
	do{
		buf[len++] = x % 10 + '0';
	}while(x/=10);
	while(len--){
		putchar(buf[len]);
	}
}
int main(){
	int a,b;
	read(a);
	read(b);
	write(a+b);
	return 0;
}

让我们理解一下代码:一开始使用了一个cpu加速的命令,然后就是熟悉的快读快写代码了。如果你不熟悉,你可以记一下,这个十分有用。

到这里,这篇题解就写完了,祝每个看到并点赞的大神犇都能AK IOI!!!

原文