Pagini recente » Cod sursa (job #304146) | Cod sursa (job #1440386) | Cod sursa (job #1633491) | Cod sursa (job #3171789) | Cod sursa (job #187720)
Cod sursa(job #187720)
//Quadtrees
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define LL long long
#define ULL unsigned long long
#define PB push_back
using namespace std;
struct P{
int X,Y,Z;
};
struct Tree{
int val,Y,Z;
Tree *A1,*A2,*B1,*B2;
Tree(int r1,int r2,int r3) {
val = r1;
Y = r2;
Z = r3;
A1 = NULL;
A2 = NULL;
B1 = NULL;
B2 = NULL;
}
};
vector <P> A;
vector<P>::iterator it;
int set(P *who,Tree *&cur){
if (cur == NULL){
cur = new Tree( (who->X)+1, who->Y, who->Z);
return who->X+1;
}
//cout << who->Y << " " << cur-> X << "\n";
if ((who->Y > cur -> Y) && (who->Z > cur -> Y)){
who->X = cur->val;
//cout << who->X<<" ";
return set(who,cur->A2);
}
if ((who->Y > cur -> Y) && (who->Z < cur -> Y))
return set(who,cur->B2);
if ((who->Y < cur -> Y) && (who->Z > cur -> Y))
return set(who,cur->A1);
if ((who->Y < cur -> Y) && (who->Z < cur -> Y))
return set(who,cur->B1);
}
int comp(P a,P b){
return (a.X) < (b.X);
}
int main(void){
ifstream in("cutii.in");
ofstream out("cutii.out");
int N,T,i,j,max,sol;
Tree *root;
root = NULL;
in >> N >> T;
P np;
while (T){
for (i=0;i<N;i++){
in >> np.X >> np.Y >> np.Z;
A.PB(np);
}
sort(A.begin(),A.end(),comp);
max = 0;
for (it=A.begin();it<A.end();it++){
np = *it;
//out << np.X << " " << np.Y << " " <<np.Z << " | ";
np.X = 0;
sol = set(&np,root);
if (sol>max) max = sol;
}
out << max << "\n";
root = NULL; //not too nice :D
A.clear();
T--;
}
in.close();
out.close();
return 0;
}