Xidian Online Judge WebBoard
 Problem 1001 >> 这提示有毒？ 14030110093 @ 2017-05-19 23:21:12 [ Quote ] [ Edit ] [ Delete ] 1# 输入数据只保证n*m在106以内，也就是说n和m都可能高达106。直接开106*106的数组肯定会MLE，请自行管理内存。 我提交了这份代码，直接开二维数组，为什么没有MLE，后台测试的数据不够大？ #include int main(){ int m,n; int total = 0; while (scanf("%d %d",&n,&m) != EOF) { total ++; printf("Case #%d:\n",total); char field[n+1][m+1];//能直接开数组？ int nown[n+1],nowm[m+1]; int i,j; for (i=1;i<=m;i++) nowm[i] = i; for (i=1;i<=n;i++){ char row[1000001]; nown[i] = i; scanf("%s",row); for (j=1;j<=m;j++){ field[i][j] = row[j-1]; } } int q; scanf("%d",&q); for (i=1;i<=q;i++){ int order,i1,i2; scanf("%d %d %d",&order,&i1,&i2); if (order == 1){ char now = field[nown[i1]][nowm[i2]]; if (now == 'T'){ printf("Tree\n"); } else if (now == 'i'){ printf("Phone\n"); } else printf("Empty\n"); } if (order == 2){ int temp = nown[i1]; nown[i1] = nown[i2]; nown[i2] = temp; } if (order == 3){ int temp = nowm[i1]; nowm[i1] = nowm[i2]; nowm[i2] = temp; } } } return 0; } xry111 @ 2017-05-20 20:07:39 [ Quote ] [ Edit ] [ Delete ] 2# This is a variable length array. It's not $10^6 \times 10^6$. I don't like VLA since it's not conform to each version of C++ Standard. VLA is just a GNU extension, with a bunch of bugs. See . You may get strange WA/RE if you use VLA in an important contest (Murphy Law). In fact GCC users and developers aren't enthusiastic to fix VLA bugs. They just use -Werror=vla for C++. But VLA is fully C99 standard. So use VLA in C99 (which is the C standard of XDOJ) is alright. But still you should notice that VLAs are on the stack. If you have a large VLA it may lead to SIGSEGV. In this problem the VLA is just 1M and the stack limit of XDOJ is 8M. Please don't criticize XDOJ administrators or problem setters for unspecified (esp. implementation-defined) or undefined behaviour. For example, glibc has O(n+m) strstr() so someone may solve a KMP problem with it (on XDOJ). You shouldn't say "It's unfair! He doesn't know how to write KMP!" And you shouldn't say "I submitted his program to Codeforces and got TLE!" And neither "I'm very clever! I can solve this problem with a single strstr() call!" And neither "The problem setter is a fool! He can't hack my strstr() program!"
[Top] [Previous Page] [Next Page]