我的代码:
#include <stdlib.h>
#include <iostream>
#include <math.h>
int main(int argc, char *argv[]) {
long long n = atoi(argv[1]);
long long m = atoi(argv[2]);
long long a = atoi(argv[3]);
if (n == 0 || m == 0 || a == 0) {
std::cout << "" << 0 << std::endl;
return 0;
}
long long num_tiles = ceil(n / a) * ceil(m / a);
if (num_tiles == 0) num_tiles = 1;
std::cout << "" << num_tiles << std::endl;
return 0;
}
这会在使用 GNU C++ 11 的 Codeforces 测试服务器上产生错误(“测试 1 上的运行时错误”)。我正在使用 g++ -std=c++11 ...
来编译我的本地代码,效果很好。对于所有其他问题解决方案,我也遇到了同样的错误。有什么想法吗?
最佳答案
这些行是罪魁祸首:
int main(int argc, char *argv[]) { long long n = atoi(argv[1]); long long m = atoi(argv[2]); long long a = atoi(argv[3]);
在 Online Judges 中,您必须从标准输入 (STDIN) 获取输入并输出到标准输出 (STDOUT)。
使用任何标准方法,如 scanf
或 cin
获取您的输入并使用 printf
或 cout
给出你的输出。不要期望 argc
或 argv
中有任何有用的东西。
看看这个FAQ on Codeforces .
摘自另一名网络评委Codechef ,这也适用于 Codeforces。
If you use any method other than using the standard input and output streams - for example, using command line arguments, reading from a file, opening up some sort of dialog box, or otherwise - you will never be judged correct.
关于c++ - Codeforces 测试服务器错误,无法在本地机器上重现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39968867/