fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int matrix[2][101], ord[101], n, count = 1;
  6.  
  7. void sort() {
  8. int finished = 0, size = n, swapped;
  9. while(!finished) {
  10. swapped = 0;
  11. for(int i = 1; i < size; ++i) {
  12. if(matrix[1][ord[i]] > matrix[1][ord[i+1]]) {
  13. int temp = ord[i];
  14. ord[i] = ord[i+1];
  15. ord[i+1] = temp;
  16. swapped = 1;
  17. }
  18. }
  19. if(swapped) size--;
  20. else finished = 1;
  21. }
  22. }
  23.  
  24. int main(int argc, char const *argv[]) {
  25.  
  26. int start,
  27. end;
  28.  
  29. //freopen("spectacole.in", "r", stdin);
  30.  
  31. //freopen("spectacole.out", "w", stdout);
  32.  
  33. cin>>n;
  34.  
  35. for(int i = 1; i <= n; ++i) {
  36. ord[i] = i;
  37. cin>>start>>end;
  38. matrix[ 0 ][ i ] = start;
  39. matrix[ 1 ][ i ] = end;
  40. }
  41.  
  42. sort();
  43.  
  44. int curr = matrix[1][ord[1]];
  45.  
  46. for(int i = 2; i <= n; ++i) {
  47.  
  48. if(matrix[0][ord[i]] >= curr) {
  49.  
  50. curr = matrix[ 1 ][ ord[ i ] ];
  51.  
  52. count++;
  53. }
  54. }
  55.  
  56. cout<<count;
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0.01s 5516KB
stdin
10
5 14
14 17
8 13
13 15
15 17
3 6
4 7
6 9
11 14
10 11
stdout
5