在非交互的,有很多查询的题目中,忘记 cin.tie(0) 会导致每次从 cin 读取数据时刷新输出缓冲区,导致程序超时。
在交互题中,使用 cin.tie(0),且不使用 endl 或 flush 会导致程序不刷新输出缓冲区,导致空闲时间超时 (Idle Limit Exceeded)。
int main()
{
ios::sync_with_stdio(false);
int a, b;
while (cin >> a >> b)
cout << a + b << '\n';
return 0;
}
这个 a+b 程序在数据组数很多时,由于每次使用 cin 读取数据都会刷新输出缓冲区,可能超时。
使用文本编辑器,在代码中查找 cin.tie(0)。
cin/cout,就使用 cin.tie(0)。cin.tie(0)。