题目地址:http://poj.org/problem?id=1833
在poj上G++没过,C++过了,下面摘的网上的解释。
G++是一个GNU编译器,而C++是微软VC++的编译器。这两种编译器对不同的地方有优化,因此速度谁快谁慢不一定吧。有些题目使用C++提交相同的代码运行时间只有G++的八分之一,很是让人费解(可能是POJ是windows为基础的原因吧)。G++中对栈内存有优化,允许定义这样的数组: int a[n]; (n为变量)。不过C++中有些可以使用的函数在G++中是没有的,这点要注意啊。所以很多C++编译通过的代码到G++上就CE了,对于G++也是如此。而且貌似两种编译器的编译的程序在浮点数精度控制上有差异。一些计算几何题目使用G++就WA,而使用C++就可AC。虽然我写代码一直用G++,但是这个的具体原因也搞不清出。#include <iostream> #include <cmath> #include <string> #include <cstring> #include <cstdlib> #include <ctime> #include <algorithm> #include <cstdio> using namespace std; typedef long long ll; #define INF 0xfffffff #define MAX(a,b) a>b?a:b #define MIN(a,b) a>b?b:a #define N 1050 int a[N]; int main() { int i,j,k,t; int m,n; cin>>t; bool x; while(t--) { scanf("%d%d",&n,&k); for(i=0;i<n;i++) scanf("%d",&a[i]); while(k--) { x = next_permutation(a,a+n); if(!x) sort(a,a+n); } printf("%d",a[0]); for(i=1;i<n;i++) printf(" %d",a[i]); printf("\n"); } return 0; }