全局变量在 C++ 中是否显着提高了编译速度?
Does global variable increase speed of compilation significantly in c++?
对于一个问题
https://codeforces.com/problemset/problem/760/B
当我提交在 int main(( 中具有声明的解决方案时,它显示 TLE,但是当声明高于 int main(( 时,它在 C++ 中被接受。
所以我的问题是全局声明是否显着影响编译速度或我错过了什么?
这是公认的:
#include<bits/stdc++.h>
using namespace std;
int n,k,m,a=1,c=1;
int main()
{
cin>>n>>m>>k;
m -= n;
while (m>0){
if (k+a<=n) c++;
if (k-a>=1) c++;
m -=c;
a++;
}
cout<<a;
return 0;
}
这是TLE一:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,m,a=1,c=1;
cin>>n>>m>>k;
m -= n;
while (m>0){
if (k+a<=n) c++;
if (k-a>=1) c++;
m -=c;
a++;
}
cout<<a;
return 0;
}
应该没有区别。 如果您的样本量很小(您提交了一两次解决方案(,也许您处于超出时间限制与未超出时间限制的边界,有时只是很幸运。
相关文章:
- 如何构建模板的显式实例化以提高编译速度?
- 全局变量在 C++ 中是否显着提高了编译速度?
- std::结构复杂,使编译速度变慢
- 如何刻意减慢编译速度?
- JIT 编译的运行速度能否比编译时模板实例化更快?
- 如果我用代码块编译代码,为什么我的代码运行速度更快
- 跟踪gcc编译以及哪些代码会减慢编译速度
- 嵌套的lambda表达式在用Visual C++编译和生成巨大的对象文件时速度非常慢
- 不同计算机的算法与预编译引用实现的速度比不同
- 矢量模板的编译速度是否比push_back快
- 初始化包含7000个元素的容器时,编译速度较慢
- 自动生成的依赖项导致编译速度缓慢
- 调试版本的编译速度比发布慢得多
- 为什么多个文件的编译速度比合并文件快得多
- 在PInvoke中管理大量的第三方依赖关系,以提高编译速度
- 编译速度的改进包括防护与预编译头文件的对比
- 剖析c++代码的编译速度
- 提高Rcpp编译速度
- 通过分发目标文件加快编译速度
- 编译速度对于一个项目(大约2000行)来说太慢了