|
|
вернуться в форумWhy does my program not work? //I received an error: Crash (ACCESS_VIOLATION) from the judge // USU Problem 1146 // Maximum Sum // Done by Teh Ming Han #include <iostream.h> #include <fstream.h> int main(){ int x1,y1,x2,y2,n,c,max=0; int sum[100][100], work[100][100]={0}; ifstream infile("maxsum.in"); infile>>n; for (x1=1;x1<=n;x1++) for (y1=1;y1<=n;y1++) infile>>sum[x1][y1]; //read data infile.close(); for (x1=1;x1<=n;x1++) for (y1=1;y1<=n;y1++) for (x2=1;x2<=x1;x2++) for (y2=1;y2<=y1;y2++) work[x1][y1] += sum[x2][y2]; for (x1=1;x1<=n;x1++) for (y1=1;y1<=n;y1++) for (x2=x1;x2<=n;x2++) for (y2=y1;y2<=n;y2++){ c = work[x2][y2] - work[x1-1][y2] - work[x2][y1-1] + work[x1-1][y1-1]; if (c>max) max=c; } ofstream outfile("maxsum.out"); outfile<<max; outfile.close(); return 0; } Re: Why does my program not work? Послано Nebula 16 апр 2004 13:52 N may be as large as 100 lucky~ You'll get TLE. As I see your program is O(N^4) and it's to many operations when N = 100. Re: You'll get TLE. Послано sloboz 16 апр 2004 20:22 your algo is good, theoretically is N^4 but practically fits in time. First you must not use files, and second put 200 or 110 or something little larger than 100. You'll get AC (I sent your source with these modifications). Re: what's wrong u use files. try using scanf/cin printf/cout Re: Why does my program not work? Послано Lakers 18 ноя 2011 22:14 use for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + a[i][j]; } } |
|
|