Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这么长。。。。。

Posted by Lucifer at 2005-11-01 02:04:43 on Problem 2376
In Reply To:郁闷!老是WA!是否有特殊的情况?请指教。附上我的源代码。 Posted by:kingway at 2005-04-06 15:26:03
> #include <iostream>
> #define TYPE shift
> 
> using namespace std;
> 
> class shift {
> 	public :
> 	int start;
> 	int end;
> 	bool operator>= (shift s) {
> 		if (start > s.start || (start == s.start && end >=s.end)) {
> 			return true;
> 		}
> 		else 
> 			return false;
> 	}
> 	
> 	bool operator<= (shift s) {
> 		if (start < s.start || (start == s.start && end <=s.end)) {
> 			return true;
> 		}
> 		else
> 			return false;
> 	}
> 	
> 	void operator= (shift s) {
> 		start = s.start;
> 		end = s.end;
> 	}
> };
> 
> shift shifts[25001];
> 
> // Quit sorting
> 
> int Partition(TYPE list[], int low, int high) {
> 	TYPE pivotkey;
> 	list[0] = list[low];
> 	pivotkey = list[low];
> 	while (low < high) {
> 		while (low < high && list[high] >= pivotkey)
> 			--high;
> 		list[low] = list[high];
> 		while (low < high && list[low] <= pivotkey)
> 			++ low;
> 		list[high] = list[low];
> 	}
> 	list[low] = list[0];
> 	return low;
> }
> 
> void QuitSort(TYPE list[], int low, int high) {
> 	int pivotloc;
> 	if (low < high) {
> 		pivotloc = Partition(list, low, high);
> 		QuitSort(list, low, pivotloc - 1);
> 		QuitSort(list, pivotloc + 1, high);
> 	}
> }
> 
> int main() {
> 	
> 	int n, t, i, j, count = 0;
> 	
> 	cin >> n >> t;
> 	
> 	for (i=1; i<=n; i++) {
> 		// cin >> shifts[i].start >> shifts[i].end;
> 		scanf("%d%d", &shifts[i].start, &shifts[i].end);
> 	}
> 	
> 	QuitSort(shifts, 1, n);
> /*
> 	for (i=1; i<=n; i++) {
> 		cout << shifts[i].start << " " << shifts[i].end << endl;
> 	}
> 	*/
> 
> 	int end = 0;
> 	int newend = 0;
> 	
> 	if (shifts[1].start != 1) {
> 		cout << "-1";
> 		return 0;
> 	}
> 	else {
> 		count++;
> 		for (i=1; i<=n; i++) {
> 			if (shifts[i].start == 1) {
> 				if (shifts[i].end == t) {
> 					cout << count;
> 					return 0;
> 				}
> 				end = shifts[i].end;
> 			}
> 			else
> 				break;
> 		}
> 	}
> 	
> 	for (; i<=n; i++) {
> 		if (shifts[i].start <= end + 1) {
> 			if (newend < shifts[i].end) {
> 				newend = shifts[i].end;
> 			}
> 		}
> 		else {
> 			if (newend == 0) {
> 				cout << "-1";
> 				return 0;
> 			}
> 			else {
> 				count ++;
> 				
> 				if (newend == t) {
> 					cout <<  count;
> 					return 0;
> 				}
> 				end = newend + 1;
> 				//cout << "!!!" << end <<endl;
> 				newend = 0;
> 				i--;
> 			}
> 		}
> 	}
> 	
> 	if (newend == t) {
> 		cout << (count + 1);
> 	}
> 	else {
> 		cout << "-1";
> 	}
> 	
> 	return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator