Hey man, I think its a lot of work to change size of your vectors like that
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <vector>
template<typename T> //default argument
std::vector<std::vector<std::vector<T>>> make_3d_vector(int z, int y, int x, T value = T{})
{
return std::vector<std::vector<std::vector<T>>>(z, std::vector<std::vector<T>>(y, std::vector<T>(x, value)));
}
int main()
{
//specify dimensions and last arg is value to initialize elements if you don't like default 0
auto 3d_vec = make_3d_vector<int>(10, 10, 10, 20);
std::cout << 3d_vec [5][5][5]; //20
}
This is also more efficient if all you want to do is to create specific size 3d vector
So it would be easier to understand this is how you create 1d and 2d vectors with specific size
@tomtran have you thought about using other stl structures? Stacks, Queues, Lists, Maps, Sets, and or combining them with tuples or pairs? I mean you can probably use vectors all the way, but it might be easier to wrap your head around your data struct if you were using different abstractions.
@keskiverto:
1. Each line contains 4 integers, I'm sure, cuz the spec says so.
2. time won't be wrong cuz I've double check it with my friends about the range.
This hold true until the next line of the integer c is actually c itself. For example: If the size of c is 10 and c in the next line is 10. Then at(10) will be the problem. I get it!!
My prof. took a task similar to KDDCUP2012 track1 for assignment. I handed it in already. But I kinda feel like to find out any faster way to approach.
Data set format:
(UserId)\t(ItemId)\t(Result)\t(Unix-timestamp)
Result: values are 1 or -1, where 1 represents the user UserId accepts the recommendation of item ItemId, and -1 represents the user rejects the recommended item.
5 actions to perform:
accept(u,i,t): outputs the (Result) when user u is given item i at time t.
items(u1, u2): outputs the sorted (ItemId), line by line, that are recommended to both user u1 and user u2.
users(i1,i2,t1,t2): outputs the sorted (UserId), line by line, which corresponds to users who are given both item i1 and item i2 between the time interval [t1,t2].
ratio(i,threshold): outputs the acceptance rate of item i among the users who have been given items for more than threshold times. The format of your output is (#accept)/(#total) .
For instance, ratio(10, 78) = 14/101 means there are 101 users who are given any items by the system for more than 78 times. Among them, 14 users (remove duplication) have accepted item 10.
findtime item(i, Us): outputs the sorted list of timestamps (remove duplication), line by line, that correspond to when item i is given to any member from a group of users Us. You can choose your implementation of Us.
And by the way, what is tuple? As Bdanielz suggest, I would like to know how to use it? Any link that has asked this question is fine.