MAP

Time Limit: 1000 MS Memory Limit: 65536 KB

64-bit integer IO format: %I64d , %I64u Java class name: Main

[Submit] [Status] [Discuss]

Description

Many people get information from Baidu、Google、Bing and so on. OK, now we will consider how to test the performance of a search system.
The testing is based on an annotation file,annotation file consist of some query,every query has a query word and many reference URL. For example,“MM xxoo.com ooxx.com xoxo.com”,“MM”is the query word and “xxoo.com ooxx.com xoxo.com”is the reference URL.
If we search the query word from search system, we can also get a result list, and then we can test the search performance by the result list and annotation file. You job is calculate the MAP of the search performance. The definition of MAP is:
Rank:
Position of a retrieved URL in the list of retrieved list.
Precision at a given cut-off rank r for a single query:
P(r) = (number of relevant URL of rank r or less) / r
Average precision: defined as follows

Where N is the number of retrieved URL, R is the number of relevant URL, and rel(r) = 1 if URL at rank r is relevant, 0 otherwise.
Mean average precision: average precision for a set of queries is defined as follows:

Where Q is the number of queries.

Input

The first line of input contains T, the number of test cases.
For each test case start with a number n, the query number of annotation file. Then follows 2n lines, the first n lines are the annotation, every line means a query that has a word in front and the reference URL followed. The next n lines are the search result of the queries in annotation, every line means the search result of a query that has the search word in front and the retrieved URL followed.
n <= 100.
The length of a line <= 10000.
The length of a URL and word <= 50.

Output

Case number ant the MAP value with 6 digits after decimal point.

Sample Input

1
3
Banana banana.com
Apple iphone.com ipad.com
Software Microsoft.com IBM.com Google.com
Banana asd.com banana.com
Apple gdfgd.com iphone.com ipad.com
Software gdf.com wer.com tre.com

Sample Output

Case #1: 0.361111

Source

2012 Multi-University Training Contest 3
题目大意:
一个网址:MM xxoo.com ooxx.com xoxo.com  包括一个疑问词:MM,若干个数的URL: xxoo.com ooxx.com xoxo.com (3个URL)。题目说测试搜索引擎的性能,先输入一个网址,会返回一个网址(后输入的网址),称先输入网址的URL为相关URL(relevant URL),称后输入的URL为retrieved URL。
rank :Position of a retrieved URL in the list of retrieved list.:后输入的URL在它所在的URL列表中的位置。
P(r) = (number of relevant URL of rank r or less) / r  = (后输入的在 rank  r  以内的相关URL的个数,可能为0)/r
N:后输入的URL的个数
R:先输入的URL的个数
rel(r):若后输入的URL与先输入的URL相同则为1,不同则为0 
Q:疑问词MM的个数
解题分析:
按照题意输入,按公式模拟,用map数组标记先输入的URL,值得注意的是,从URL列表中提取每个URL时,用到了 istringstream类,它在一个长字符串中提取用空格隔开的字符的。
例:
 1 #include<iostream>
 2 #include<sstream>        //istringstream 必须包含这个头文件
 3 #include<string>
 4 using namespace std;
 5 int main()
 6 {
 7     string str="i am a boy";
 8     istringstream a (str);
 9     string s;
10     while(a>>s)  //提取一个单词s且s不为空
11     {
12         cout<<s<<endl;
13     }
14      return 0;
15 }

解题代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<map>
 5 #include<sstream>
 6 using namespace std;
 7 #define N 110
 8 #define M 10005
 9 int R[N];
10 char a[M];
11 map<string,int>mp[N];
12 void Init(int k)
13 {
14     istringstream str(a);   ///istringstream是一个类,str为它的一个对象
15                             ///这里使用构造函数接受一个字符串a
16     string tmp;
17     int tot = 0;
18     str >> tmp; ///提取一个单词,空格用于区分单词,不可能被提取到单词中
19                 ///其实如果自己模拟出错,应该就是把空格提到了单词中
20                 ///这个语句是把MM提取出来了
21     mp[k].clear();
22     while(str >> tmp){ ///开始提取先输入的URL
23         tot++;
24         mp[k][tmp] = 1;
25     }
26     R[k] = tot;   ///得到的是先输入的URL的个数
27 }
28 double Get_AveP(int k)
29 {
30     istringstream str(a);
31     string tmp;
32     int r = 0,u = 0;    ///p(r)=u/r
33     double res = 0;
34     str >> tmp;     ///提取后输入的MM
35     while(str >> tmp){  ///提取后输入的URL
36         ++r;
37         if(mp[k][tmp] == 1)
38         {
39             u++;
40             res += u*1.0/r; ///res就是rel为1的时候p(r)的累加和
41         }
42     }
43     return res/R[k];
44 }
45 int main()
46 {
47     int t,n,ca=0;
48     scanf("%d",&t);
49     while(t--)
50     {
51         scanf("%d",&n);
52         getchar();
53         for(int i = 1; i <= n; i++)
54         {
55             gets(a);
56             Init(i);
57         }
58         double MAP = 0.0;
59         for(int i = 1; i <= n; i++)
60         {
61             gets(a);
62             MAP += Get_AveP(i);
63         }
64         MAP /= n;
65         printf("Case #%d: %.6lf\n",++ca,MAP);
66     }
67     return 0;
68 }

转载于:https://www.cnblogs.com/yangxingzhe8102/p/5939264.html

G -- HDU 4329 MAP相关推荐

  1. 暑期集训5:并查集 线段树 练习题G: HDU - 1754

    2018学校暑期集训第五天--并查集 线段树 练习题G  --   HDU - 1754 I Hate It 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.  这让 ...

  2. 暑期集训3:几何基础 练习题G: HDU - 1052

    2018学校暑期集训第三天--几何基础 练习题G  --   HDU - 1052   (昨天加练题) Tian Ji -- The Horse Racing Here is a famous sto ...

  3. hdu 5199 map或二分或哈希

    题目描述:给出n棵树的高度,每棵树上都站着一只鸟,枪手Jack站在最左边那棵树的左边对鸟进行射击,当Jack在高度为H的地方向右发射一颗子弹的时候,高度为H的树上的鸟儿就会掉落(注:其他树上的鸟儿不会 ...

  4. hdu 1075 map

    题意:给一个字典,和一句话,翻译一下 奇怪的格式 Sample Input START from fiwo hello difh mars riwosf earth fnnvk like fiiwj ...

  5. hdu 1247 map

    818786 asia2562219 C Accepted 4464 KB 218 ms C++ 615 B 2012-11-17 16:05:08 写个了字典树 但又发现map 这个以前没用过的 容 ...

  6. hdu 4921 Map(组合计数)

    题意:给出一些拼图,选择其中一些来组成地图,有的拼图需要其他拼图才能使用,每个拼图有一个价值,每一层根据选中的拼图有价值加成,问最终选择拼图价值的情况是多少. 思路:其实也就是计算所有情况的价值和除情 ...

  7. 省赛训练3 G HDU 1759 Matrix Revolution(BFS)

    Matrix Revolution Time Limit: 3000 ms /Memory Limit: 32768 kb Description Lele 现在不仅会整数A+B,A*B,还会矩阵A+ ...

  8. HDU 4921 Map

    题意: 给n个节点  他们形成了最多10条链  每条最多1000的长度  每个节点有个val  你可以选择任意位置截断链  断点前的所有节点被你获得  通过题中计算公式得出你的val  问  通过随机 ...

  9. HDU 4921 Map(状态压缩)

    题意看这篇博客. 思路参考的这篇博客. 补充:面对这种问题有一个常见的套路.比如计算若干个区间对答案的贡献这种问题,直接暴力可能复杂度到O(n ^ 2), 而我们可以计算出每个元素在多少个合法区间中, ...

最新文章

  1. 【代码实现接口测试】Requests库
  2. arcengine 将地图文件保存为图片(包括各种图片格式)
  3. asp.net学习之再论sqlDataSource 1
  4. HTML JQuery 技巧总结
  5. 关于直播,所有的技术细节都在这里了(三)
  6. dd命令打包多个文件_linux下如何tar打包多个并列文件夹,如:将a文件夹 b文件夹 c文件夹,打包成d.tar文件...
  7. linux 配置java环境变量_linux配置java环境变量(详细)
  8. C++ PRIMER 5TH 课后题答案1.16
  9. 最新最全MTK联发科手机芯片型号及参数汇总
  10. SQL Server常用函数整理
  11. 西点教育计算机二级证,拍了拍你:西式面点师证报名报考政策须知
  12. 什么是AWS Fargate
  13. python中时间加一个小时
  14. 【数据结构】栈的简单理解以及对栈的基本操作
  15. HTML学生个人网站作业设计:公益专题扫黑除恶(HTML+CSS)
  16. 怎样最大程度获得谷歌精选摘要(featured snippets)
  17. qu32调音台说明书_使用QU32调音台录制辩论赛音频
  18. Python 数据分析——Matplotlib相关知识
  19. 计算机组装模拟网址,装机模拟器PC Building Simulator-电玩之家
  20. JAVA实验四:写一个彩票的模拟程序

热门文章

  1. 【系统救援】/lib64/libnssutil3.so: version `NSSUTIL_3.59‘ not found (required by /lib64/libnss3.so)
  2. 身体语言密码_《身体语言密码》人如果整天揣摩别人的心思,那就太可悲了
  3. HP Unix 命令整理
  4. COOX培训材料 — PMT(1.Phase)
  5. PHP传说中的三码合一
  6. 如何在线重装Win10?Win10电脑系统重装详细教程
  7. IDEA行前边有个对勾的解决方法
  8. urdf、xacro、sdf三种文件的转换
  9. 怎么停掉或关闭运行的npm run dev
  10. 安卓查看wifi密码