Cod sursa(job #73192)

Utilizator andrei.12Andrei Parvu andrei.12 Data 17 iulie 2007 12:24:33
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#include<stdio.h>
#include<stdlib.h>
int nr;
struct cutie{
	int a, b, c;
};
cutie v[3505];
int comp(const void*x, const void*y){
	cutie xx=*(cutie*)x, yy=*(cutie*)y;
	if (xx.a<yy.a) return -1;
	if (xx.a>yy.a) return 1;
	return 0;
}
struct ches{
	int q, w;
};
ches s[3505];
void caut(int x, int y){
	int li = 1, ls = nr, p;
	while (li<=ls){
		p = (li+ls)/2;
		if (s[p].q==x && s[p].w==y){
			s[p].q = x;
			s[p].w = y;
			return;
		}
		if ((s[p].q<x && s[p].w>y) || (s[p].q>x && s[p].w<x)){
			s[++nr].q = x;
			s[nr].w = y;
			return;
		}
		if (s[p].q<x && s[p].w<y)
			li = p+1;
		else
			if (s[p-1].q<x && s[p-1].w<y){
				s[p].q = x;
				s[p].w = y;
				return;
			}
			else
				ls = p-1;
	}
	s[++nr].q = x;
	s[nr].w = y;
}
int main()
{
	freopen("cutii.in","r",stdin);
	freopen("cutii.out","w",stdout);
	int n, t, nrt, i;
	scanf("%d%d", &n, &t);
	for (nrt=1; nrt<=t; nrt++){
		for (i=1; i<=n; i++)
			scanf("%d%d%d", &v[i].a, &v[i].b, &v[i].c);
		qsort(v, n+1, sizeof(v[0]), comp);
		nr=1;
		s[nr].q	= v[1].b;
		s[nr].w	= v[1].c;
		for (i=2; i<=n; i++)
			caut(v[i].b, v[i].c);
		printf("%d\n", nr);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}