本文遵循 CC BY-NC-SA 4.0二创协议
今天居然是 noip 上课
快读
比较时间
-
cin,cout时间爆表仅可以过
-
cin,cout关闭输入输出流,可以过
- 关闭方法如下:
C++ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); -
scandf,比cin,cout慢,也可以过
-
快读 全对
写法
inline int read()
{
int x = 0,f=1;
char ch = getchar();
while(!isdigit(ch))
{
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch))
{
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}冷知识:noip在提交时还写错了
题目练习——A+B快速版
注:本题和这道题类似
题目描述
给定 对数 ,求出所有的 。
输入描述
第一行输入
接下来 行每行有两个整数
输出描述
输出 行, 对 的结果
输入样例
2
1 1
2 2输出样例
2
4数据范围
题目解析
这道题的数据范围有点点大,如果使用正常的读入肯定会TLE,所以,我们要使用快读。
根据上面写方法,便可以写出一下代码:
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x = 0,f=1;
char ch = getchar();
while(!isdigit(ch))
{
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch))
{
x=x*10+ch-'0';
ch=getchar();
}
return f*x;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int k = read();
while(k--){
int x=read(),y=read();
cout<<x+y<<"\n";
}
return 0;
}这样就可以完美通过此题
更方便的快读
因为数据不可能只是int类型,如果变成long long就得重新写一份,很容易出错。那么,我们便可以用这个代码。
template <typeame T>意思:处理多种数据类型 使用方法:加在函数前
github链接
该内容包含单独代码(.cpp),此文章(.md),以及题目(.md)。
- 代码:
- 文章:
- 题目:
FileCodeBox链接
该内容包含代码(.zip),以及此文章(.md),包含题目(.md)