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);
}

2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题的更多相关文章

  1. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力

    Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...

  2. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉

    Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...

  3. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题

    Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...

  4. 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...

  5. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题

    Problem J. Joke 题目连接: http://codeforces.com/gym/100714 Description The problem is to cut the largest ...

  6. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题

    Problem H. Hometask 题目连接: http://codeforces.com/gym/100714 Description Kolya is still trying to pass ...

  7. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem F. Finance 模拟题

    Problem F. Finance 题目连接: http://codeforces.com/gym/100714 Description The Big Boss Company (BBC) pri ...

  8. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem A. Alien Visit 计算几何

    Problem A. Alien Visit 题目连接: http://codeforces.com/gym/100714 Description Witness: "First, I sa ...

  9. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem D. Grumpy Cat 交互题

    Problem D. Grumpy Cat 题目连接: http://www.codeforces.com/gym/100253 Description This problem is a littl ...

随机推荐

  1. js 隐藏代码生成工具

    昨天写了篇<js 奇葩技巧之隐藏代码>,今天来写个工具方便大家生成吧.在昨天算法基础上优化了解码算法,采用立即函数运行.有两种模式可供选择: 1. eval  全局模式,比如你定义的 va ...

  2. 控制台console对象常用的一些方法

    console.log():调试中最常用的方法,用于在控制台窗口显示信息. console.log(123); console.warn():输出信息时,在最前面加一个黄色三角,表示警告 consol ...

  3. 解决PHP curl https时error 77(Problem with reading the SSL CA cert (path? access rights?))

    服务器环境为CentOS,php-fpm,使用curl一个https站时失败,打开curl_error,捕获错误:Problem with reading the SSL CA cert (path? ...

  4. 20155227 2016-2017-2 《Java程序设计》第五周学习总结

    20155227 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 语法与继承架构 使用try...catch JVM会尝试执行try区块中的程序代码,如果发生 ...

  5. laravel一个页面两个表格分页处理

    关键是看懂laravel自带的 paginate() 方法. 在Builder.php文件(项目名称/laravel/vendor/laravel/framework/src/Illuminate/D ...

  6. 关于cookie和session

    在设置cookie的时候,它会保留在本地,无论你有没有退出浏览器都是.但是session只能在登录状态有效.退出浏览器过后就会消除掉.同时设置也是有问题的. @app.route('/login',m ...

  7. Dream_Spark-----Spark 定制版:004~Spark Streaming事务处理彻底掌握

    Spark 定制版:004~Spark Streaming事务处理彻底掌握 本讲内容: a. Exactly Once b. 输出不重复 注:本讲内容基于Spark 1.6.1版本(在2016年5月来 ...

  8. 【PE结构】恶意代码数字签名验证

    说明 恶意代码数字签名验证功能,WinverityTrust.CryptQueryObject 代码实现 WinVerifyTrust //------------------------------ ...

  9. 在Scrapy项目【内外】使用scrapy shell命令抓取 某网站首页的初步情况

    Windows 10家庭中文版,Python 3.6.3,Scrapy 1.5.0, 时隔一月,再次玩Scrapy项目,希望这次可以玩的更进一步. 本文展示使用在 Scrapy项目内.项目外scrap ...

  10. 【oracle】入门学习(一)

    一直想学oracle但都没有下定决心.这次借了书,一定要学好oracle. 目前学习 <Oracle从入门到精通> 明日科技 的Oracle 11g 版本 关系型数据库的基本理论 数据模型 ...