1 solutions
-
0
C++ :
#include <iostream> #include<cstdio> int fnPartition(int a[], int low, int high) { int i,j; int x = a[low]; i = low; j = high; while(i <j) { while(i <j && x <a[j]) j = j-1; if(i <j) { a[i] = a[j]; i++; } while(i <j && x>=a[i]) i++; if(i <j) { a[j] = a[i]; j--; } } a[i] = x; return i; } void fnQuickSort(int a[],int low, int high) { int pos; if(low < high) { pos = fnPartition(a,low,high); fnQuickSort(a,low,pos-1); fnQuickSort(a,pos+1,high); } }//快排 int fnSchedule(int a[],int b[],int s,int e) { int n=0; int i=s+1; if (a[s]>-1) { n = 1; for(; i <=e; i++) if(a[i]>=b[s]) s++; else n++; } return n; } int main(void) { int n,i; while(1 == scanf("%d",&n)) { int *st = new int [n]; int *et = new int [n]; for (i = 0; i <n; i++) scanf("%d %d",&st[i],&et[i]); fnQuickSort(st,0,n-1); fnQuickSort(et,0,n-1); printf("%d\n",fnSchedule(st,et,0,n-1)); delete []st; delete []et; } return 0; }
- 1
Information
- ID
- 698
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By