2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题

news/2024/7/24 11:17:02 标签: 数据结构与算法

Problem I. Interest Targeting

题目连接:

http://codeforces.com/gym/100714

Description

A unique display advertisement system was developed at the department of advertising technologies,
Yaagl Inc. The system displays advertisements that meet the interests of the user who is currently
watching the page.
For this system to function properly, having a good method for computing the user’s category of interest
and the probability of clicking an advertisement, which is related to his/her interests, is vital.
One of your colleagues has implemented an algorithm that analyzes users’ browsing history and produces
the results as follows:
user id category id create time heuristic ctr
where:
• user id is the user identifier;
• category id is the identifier of user’s predicted interest category;
• create time is the prediction generation time;
• heuristic ctr is the predicted click probability for this category.
This information is stored in interests log table.
Your task is to write a program which estimates the prediction quality. You are provided with log table
events log containing advertisement display results. Each row of the table corresponds to advertisement
display event. The table has the following columns:
• user id is the user identifier;
• category id is the identifier of an advertisement category;
• adv id is the advertisement identifier;
• show time is the advertisement display time;
• click flag is 1, if a click had occurred, 0 otherwise.
Your are expected to add new information from the first table to the second one, or, as SQL-developers
usually say, do an INNER JOIN of these two tables using (user id, category id) as a key.
While performing the join, the following conditions must be satisfied:
• user id and category id of matching rows must be equal;
• each row of the second table can match at most one row of the first table;
• for a pair of matching rows the following must hold — show time > create time and
show time − create time is minimum.
All matching rows must appear in the result. However some rows from both tables may not appear in
the result if they have no match.

Input

The first line contains the numbers interests count and events count, denoting the sizes of the
log tables interests log and events log respectively. The sizes do not exceed 70 000. The next
interests count lines contain rows of interests log, and the next events count lines contain rows
of the second table. Field values are separated by a space. All field values except for click flag are
integers belonging to the range [1, 109]. For the records in interests log, all the tuples (user id,
category id, create time) are unique.

Output

Output the joined table. Each row should be as follows:
user id category id create time heuristic ctr adv id show time click flag
Print the number of rows in the first line. Then print table rows, one per line. Order the rows by
tuples (heuristic ctr, user id, category id, create time, adv id, show time) in the ascending order.
Tuples are compared lexicographically, i.e. tuples are compared first by heuristic ctr, then by user id
and so on till show time. You can output rows in any order satisfying the described criteria.

Sample Input

2 2
1 1 102 200
2 1 104 333
2 1 33 101 0
1 1 34 105 1

Sample Output

1
1 1 102 200 34 105 1

Hint

题意

简单讲,就是给你两个表,第一个表有abcd四个属性,第二个表有abcde五个属性。

然后对于每一个第二表的项目,你都得在第一个表上找到a和b相同,但是第二个表的d和第一个表d相差最小,且大于它的项目。

然后把这两项合并一下就好了。

题解:

用set维护一下就好了,一个模拟题……

答案记得排序。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 70005;
map<pair<int,int>,int>H;
int cnt = 0;
struct people{
    int a,b,c,d;
}p[maxn];
struct ad{
    int a,b,c,d,e;
};
struct cccc{
    int a,b,c,d,e,f,g;
};
bool cmp(cccc A,cccc B){
    if(A.d==B.d&&A.a==B.a&&A.b==B.b&&A.c==B.c&&A.e==B.e)return A.f<B.f;
    if(A.d==B.d&&A.a==B.a&&A.b==B.b&&A.c==B.c)return A.e<B.e;
    if(A.d==B.d&&A.a==B.a&&A.b==B.b)return A.c<B.c;
    if(A.d==B.d&&A.a==B.a)return A.b<B.b;
    if(A.d==B.d)return A.a<B.a;
    return A.d<B.d;
}
set<pair<int,int> >S[maxn];
int getid(int x,int y){
    if(H.count(make_pair(x,y)))
        return H[make_pair(x,y)];
    H[make_pair(x,y)]=++cnt;
    return H[make_pair(x,y)];
}
int fiid(int x,int y){
    if(!H.count(make_pair(x,y)))
        return -1;
    return H[make_pair(x,y)];
}
vector<cccc> AAAAA;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        S[i].insert(make_pair(-1,-1));
        scanf("%d%d%d%d",&p[i].a,&p[i].b,&p[i].c,&p[i].d);
        S[getid(p[i].a,p[i].b)].insert(make_pair(p[i].c,i));
    }
    for(int i=1;i<=m;i++){
        ad tmp;
        scanf("%d%d%d%d%d",&tmp.a,&tmp.b,&tmp.c,&tmp.d,&tmp.e);
        int id = fiid(tmp.a,tmp.b);
        if(id==-1)continue;
        int d = (--S[id].lower_bound(make_pair(tmp.d,0)))->second;
        if(d==-1)continue;
        cccc kkk;
        kkk.a=p[d].a,kkk.b=p[d].b,kkk.c=p[d].c,kkk.d=p[d].d;
        kkk.e=tmp.c,kkk.f=tmp.d,kkk.g=tmp.e;
        AAAAA.push_back(kkk);
    }
    printf("%d\n",AAAAA.size());
    sort(AAAAA.begin(),AAAAA.end(),cmp);
    for(int i=0;i<AAAAA.size();i++)
        printf("%d %d %d %d %d %d %d\n",AAAAA[i].a,AAAAA[i].b,AAAAA[i].c,AAAAA[i].d,AAAAA[i].e,AAAAA[i].f,AAAAA[i].g);
}

转载于:https://www.cnblogs.com/qscqesze/p/5752278.html


http://www.niftyadmin.cn/n/908816.html

相关文章

Linux 服务器必备的安全设置

这里给大家推荐一款免费迭代 二开便捷的商城项目&#xff1a;源码直通车>>> 好不容易买了服务器&#xff0c;如果因为自己的疏忽&#xff0c;被黑客黑掉的话&#xff0c;那真的是太糟糕了&#xff01; 下面告诉你一些简单的方法提高服务器的安全系数&#xff0c;我的…

面向对象重载

1.使用面向对象来求两个圆之间的面积2.函数重载函数重载需要的条件&#xff1a;函数名要相同&#xff0c;参数的个数或者参数的类型不同3.this关键字虽然写在类里面&#xff0c;但不是属于类的&#xff0c;而是属于该对象的一般来说在类里面 this关键字是可以省略的&#xff0c…

VMware创建Linux虚拟机并安装CentOS(一)

在VMware中新建虚拟机&#xff0c;在新建虚拟机向导中&#xff0c;选择“自定义&#xff08;高级&#xff09;”选项&#xff0c;鼠标单击“继续”按钮 选择VMware的版本workstation9.0(VMware版本对硬盘、内存、cpu等硬件的支持大小数量不同,选择不同版本可以看到差别&#xf…

仓库管理工具Git之git clone和git pull的区别

实际应用项目&#xff1a;http://github.crmeb.net/u/long 1.需不需要本地文件夹是仓库 git clone是将整个工程复制下来所以&#xff0c;不需要本地是仓库&#xff08;没有.git文件夹&#xff09; git clone git pull需要先初始化本地文件夹文一个仓库 git pull 2.切换分支的问…

登录超时页面跳转和ajax请求时的问题!

今天闲来无事听见后端两个coder探讨如何判断请求是否是ajax请求&#xff08;通过请求头判断是否是xmlhttprequest 和ie下那个布啦布啦的东西 &#xff09;了解详情后是为了解决判断登陆超时ajax请求到的是登陆页面的html。 然后我给出了一个设计方式方最然我是一个前端&#xf…

PHP如何实现socket长连接

实际应用项目&#xff1a;http://github.crmeb.net/u/long 长连接是什么&#xff1f; 朋友们应该都见过很多在线聊天工具和网页在线聊天的工具。学校内有一种熟悉的功能&#xff0c;如果有人回复你了&#xff0c;网站会马上出现提示&#xff0c;此时你并没有刷新页面&#xf…

比较常用的正则表达式总结

这里给大家推荐一款免费迭代 二开便捷的商城项目&#xff1a;源码直通车>>> 一、校验数字的表达式 1. 数字&#xff1a;^[0-9]*$ 2. n位的数字&#xff1a;^\d{n}$ 3. 至少n位的数字&#xff1a;^\d{n,}$ 4. m-n位的数字&#xff1a;^\d{m,n}$ 5. 零和非零开头的…

python爬虫之Scrapy框架

这里给大家推荐一款免费迭代 二开便捷的商城项目&#xff1a;源码直通车>>> Scrapy是用python实现的一个为了爬取网站数据&#xff0c;提取结构性数据而编写的应用框架。使用Twisted高效异步网络框架来处理网络通信。 Scrapy架构&#xff1a; ScrapyEngine&#xff…