Open Hsue66 opened 4 years ago
/*#define U_MAX 1001
struct Record { int timestamp, like, uId; }; Record DB[T_MAX]; int dbSize, sTime; int buf[T_MAX]; bool UserTB[U_MAX][U_MAX];
inline bool compare(int i, int j) { if (sTime - DB[i].timestamp <= 1000 && sTime - DB[j].timestamp <= 1000) { if (DB[i].like > DB[j].like) return 1; else if (DB[i].like == DB[j].like) { if (DB[i].timestamp > DB[j].timestamp) return 1; else return 0; } else return 0; } else if (sTime - DB[i].timestamp > 1000 && sTime - DB[j].timestamp > 1000) { if (DB[i].timestamp > DB[j].timestamp) return 1; else return 0; } else { if (DB[i].timestamp > DB[j].timestamp) return 1; else return 0; } }
void mergesort(int *p, int len) { if (len < 2) return; int i, j, k, mid; i = k = 0; j = mid = len / 2;
mergesort(p, mid);
mergesort(p + mid, len - mid);
while (i < mid && j < len) {
if (compare(p[i], p[j]))
buf[k++] = p[i++];
else
buf[k++] = p[j++];
}
while (i < mid)
buf[k++] = p[i++];
while (j < len)
buf[k++] = p[j++];
for (register int i = 0; i < len; i++)
p[i] = buf[i];
}
void init(int N) { dbSize = 0; for (register int i = 1; i <= N; i++) { for (register int j = 1; j <= N; j++) { if (i == j) UserTB[i][j] = true; else UserTB[i][j] = false; } }
}
void follow(int uID1, int uID2, int timestamp) { UserTB[uID1][uID2] = true; }
void makePost(int uID, int pID, int timestamp) { DB[pID].like = 0; DB[pID].uId = uID; DB[pID].timestamp = timestamp; dbSize++; }
void like(int pID, int timestamp) { DB[pID].like++; }
void getFeed(int uID, int timestamp, int pIDList[]) { int s = dbSize; sTime = timestamp; int out[T_MAX] = { 0 }; int oidx = 0; while (s > 0) { //cout << oidx << " " << timestamp - DB[s].timestamp << endl; if (oidx >= 10 && timestamp - DB[s].timestamp > 1000) break; if (UserTB[uID][DB[s].uId]) out[oidx++] = s; s--; } if (oidx != 0) mergesort(out, oidx); for (int i = 0; i < 10; i++) { pIDList[i] = out[i]; //cout << out[i] << " "; } //cout << endl; } */
include
using namespace std;
define U_MAX 1001
define T_MAX 100001
struct Record { int timestamp, like, uId; }; Record DB[T_MAX]; int dbSize, sTime; int buf[T_MAX]; bool UserTB[U_MAX][U_MAX]; int Pivot;
inline bool compare(int i, int j) { if (sTime - DB[i].timestamp <= 1000 && sTime - DB[j].timestamp <= 1000) { if (DB[i].like > DB[j].like) return 1; else if (DB[i].like == DB[j].like) { if (DB[i].timestamp > DB[j].timestamp) return 1; else return 0; } else return 0; } else if (sTime - DB[i].timestamp > 1000 && sTime - DB[j].timestamp > 1000) { if (DB[i].timestamp > DB[j].timestamp) return 1; else return 0; } else { if (DB[i].timestamp > DB[j].timestamp) return 1; else return 0; } }
void mergesort(int *p, int len) { if (len < 2) return; int i, j, k, mid; i = k = 0; j = mid = len / 2;
}
void qsort(int* p, int left, int right) { if (left >= right) return; int l = left - 1; int r = right + 1; int mid = p[(l + r) / 2]; while (1) { while (compare(p[++l], mid)); while (compare(mid, p[--r])); if (l >= r) break; int temp = p[l]; p[l] = p[r]; p[r] = temp; }
}
void init(int N) { dbSize = 0; Pivot = 10; for (register int i = 1; i <= N; i++) { for (register int j = 1; j <= N; j++) { if (i == j) UserTB[i][j] = true; else UserTB[i][j] = false; } }
}
void follow(int uID1, int uID2, int timestamp) { UserTB[uID1][uID2] = true; }
void makePost(int uID, int pID, int timestamp) { DB[pID].like = 0; DB[pID].uId = uID; DB[pID].timestamp = timestamp; dbSize++; }
void like(int pID, int timestamp) { DB[pID].like++; }
void getFeed(int uID, int timestamp, int pIDList[]) { int s = dbSize; sTime = timestamp; int out[T_MAX]; int oidx = 0;
}
void show() { for (int i = 0; i <= dbSize; i++) cout << DB[i].uId << " " << DB[i].like << " " << DB[i].timestamp << endl; }
void done(){ int tmp[10]; follow(1, 2, 1); follow(2, 1, 1); getFeed(2, 534,tmp); getFeed(2, 766, tmp); getFeed(1, 1088, tmp); makePost(1, 1, 1752); like(1, 1861); makePost(1, 2, 2027); makePost(2, 3, 2117); makePost(1, 4, 2163);
}
void sample() {
}
void Test() { init(4);
}