fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int N,s,e;
  5. const int MaxN=3e4;
  6. struct LINE{
  7. int s,e;
  8. LINE(int s=0, int e=0):s(s),e(e){}
  9. }line[MaxN];
  10. bool comp(LINE lhs, LINE rhs){
  11. return lhs.s<rhs.s;
  12. }
  13. int main() {
  14. int ans=0,case_=1;
  15. while(cin>>N){
  16. for(int n=0;n<N;n++){
  17. cin>>s>>e;
  18. line[n].s=s;
  19. line[n].e=e;
  20. }
  21. sort(line,line+N,comp);
  22. for(int n=0;n<N;n++)
  23. for(int m=n+1;m<N;m++){
  24. if(line[n].e>line[m].s)
  25. ans++;
  26. }
  27.  
  28. int total=(N*(N-1))/2;
  29. cout<<"Case "<<case_<<": "<<total-ans<<"\n";
  30. case_++;
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5296KB
stdin
2
0 10
10 20
2
0 10
5 8
2
0 10
5 20
2
0 10
-5 5
2
0 10
0 10
2
0 10
5 10
5
1 5
1 5
3 10
3 10
3 10
stdout
Case 1: 1
Case 2: 0
Case 3: -1
Case 4: -2
Case 5: -3
Case 6: -4
Case 7: -5