Cod sursa(job #1851891)

Utilizator GhiciCineRazvan Dumitriu GhiciCine Data 20 ianuarie 2017 11:40:31
Problema Heavy metal Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <cstdio>
#include <algorithm>

using namespace std;

struct SPEC{
  int x,y;
};
int cmp(SPEC a, SPEC b){
  return a.y<b.y;
}
SPEC v[101];
int main(){
  FILE *f1,*f2;
  int n,i,j,cnt,k;

  f1=fopen("heavymetal.in","r");
  f2=fopen("heavymetal.out","w");
  fscanf(f1,"%d",&n);
  for(i=0;i<n;i++){
    fscanf(f1,"%d%d",&v[i].x,&v[i].y);
  }
  sort(v,v+n,cmp);
  cnt=1;
  k=v[0].y;
  for(i=1;i<n;i++){
    if(v[i].x>=k){
      cnt++;
      k=v[i].y;
    }
  }
  fprintf(f2,"%d",cnt);
  fclose(f1);
  fclose(f2);
  return 0;
}