|
|
вернуться в форумI thought that my program has no errors. But I got WA again and again. Why?? And My program procdure the correct answers for the test data in discuss. Here's My code, Help!~~!!!!!!!!!!!! Послано noname 4 фев 2003 20:34 //#define debug #include <iostream> #include <algorithm> #include <string> #ifdef debug #include <fstream> #endif using namespace std; #ifdef debug ifstream fin("in.txt"); ofstream fdebug("debug.txt"); istream& in = fin; ostream& out = cout; #else istream& in = cin; ostream& out = cout; #endif int n; struct Line{ int a,b; char color; }; Line Lines[5000]; int x[10010]; bool color[10010]; int p = 0 ; int B_Search(int k){ int head = 0; int tail = p - 1; int middle; while(head <= tail){ middle = (head + tail) / 2; if(x[middle] == k){ while(x[middle-1] == x[middle]) middle--; return middle; } if(x[middle] < k) head = middle + 1; else tail = middle - 1; } } void FloodFill(){ int i,j,t; bool IfWhite; memset(color,0,sizeof(color)); for(i=0; i<n; i++){ IfWhite = (Lines[i].color == 'w'); t = B_Search(Lines[i].b); for(j=B_Search(Lines[i].a); j<t; j++) color[j] = IfWhite; }
} int main(){ int a,b,i; in >> n; for(i=0; i<n; i++){ in >> Lines[i].a >> Lines[i].b >> Lines[i].color;
x[p++] = Lines[i].a; x[p++] = Lines[i].b; } sort(&x[0],&x[p]); FloodFill(); color[p-1] = false; int max = 0,head = x[0],t; a = 0; b = 1000000000; for(i=0; i<p; i++){ if(!color[i]){ t = x[i] - head; if(t > max){ a = head; b = x[i]; max = t; } head = x[i+1]; } } out <<a << " " << b << endl;
return 0; } I am puzzled Послано noname 4 фев 2003 20:35 You'd better not to use floodfill! > I used linetree,but.......time limited |
|
|