Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by fuckyoubitch ( 14 years ago )
#include <cstdio>
#include <cstring>
#include <algorithm>
#include<vector>
#include<stdlib.h>
using namespace std;
class STAMP{
public:
int time;
bool result;
STAMP(int ,int);
};
class TB{
public:
int username;
bool Tresult;
int counttime;
vector<STAMP>stamp;
};
class ITEM{
public:
int itemname;
TB touchby[2100];
int Tcount;
};
STAMP::STAMP(int a,int b){
time = a;
if(b==1) result = 1;
else result = 0;
}
int findI(int L,int R,ITEM item[],int itemid){
int found=0;
if(item[L].itemname==itemid) return L;
else if(item[R].itemname==itemid) return R;
while(L<=R&&!found){
int M = (L+R)/2;
if(item[M].itemname>itemid) L = M+1;
else if(item[M].itemname<itemid) R = M-1;
else found = M;
}
return found;
}
int findU(int L,int R,int name,TB t[]){
int found=0;
if(t[0].username==name) return 0;
while(L<R&&!found){
int M = (L+R)/2;
if(t[M].username>name) L = M+1;
else if(t[M].username<name) R = M-1;
else found = M;
}
if(!found) return -1;
else return found;
}
bool cmpTB(const TB &a,const TB &b){
return a.username>b.username;
}
bool cmpITEM(const ITEM &a,const ITEM &b){
return a.itemname>b.itemname;
}
int main(){
ITEM item[4170];
int Qcount=0;
int userid,itemid,result,timestamp,threshold,type=0;
FILE *f = fopen("/tmp2/KDDCUP2012/track1/rec_log_train.txt","r");
bool *Bitem = new bool[3000000];
memset(Bitem, 0, sizeof(Bitem));
while(fscanf(f,"%d%d%d%d",&userid;,&itemid;,&result;,×tamp;)!=EOF){
if(Bitem[itemid]==0){
item[Qcount].itemname = itemid;
item[Qcount].touchby[0].username = userid;
if(result=1) item[Qcount].touchby[0].Tresult = 1;
else item[Qcount].touchby[0].Tresult = 0;
item[Qcount].Tcount = 1;
item[Qcount].touchby[0].counttime=1;
item[Qcount].touchby[0].stamp.push_back(STAMP(timestamp,result));
Bitem[itemid]=1;
Qcount++;
sort(&item;[0],&item;[Qcount]+1,cmpITEM);
//++item sort;
}
else{
int Iindex = findI(0,Qcount,item,itemid);
int Uindex = findU(0,item[Iindex].Tcount,userid,item[Iindex].touchby);
if(Uindex==-1){
item[Iindex].Tcount++;
item[Iindex].touchby[item[Iindex].Tcount].username = userid;
if(result==1) item[Iindex].touchby[item[Iindex].Tcount].Tresult = 1;
else item[Iindex].touchby[item[Iindex].Tcount].Tresult = 0;
item[Iindex].touchby[0].counttime=1;
item[Iindex].touchby[0].stamp.push_back(STAMP(timestamp,result));
sort(&item;[Iindex].touchby[0],&item;[Iindex].touchby[item[Iindex].Tcount]+1,cmpTB);
}
else{
item[Iindex].touchby[Uindex].counttime++;
if(result==1&&!item[Iindex].touchby[Uindex].Tresult)
item[Iindex].touchby[Uindex].Tresult = 1;
item[Iindex].touchby[Uindex].stamp.push_back(STAMP(timestamp,result));
}
}
}
delete[] Bitem;
}
Revise this Paste