map暴力。。。

Imagine you are in the hiring process for a company whose principal activity is the analysis
of information in the Web. One of the tests consists in writing a program for maintaining up to
date a set of trending topics. You will be hired depending on the efficiency of your solution.
They provide you with text from the most active blogs. The text is organised daily and you
have to provide the sorted list of the N most frequent words during the last 7 days, when asked.
INPUT
Each input file contains one test case. The text corresponding to a day is delimited by tag
<text>. Queries of top N words can appear between texts corresponding to two different days.
A top N query appears as a tag like <top 10 />. In order to facilitate you the process of reading
from input, the number always will be delimited by white spaces, as in the sample.
Notes:
• All words are composed only of lowercase letters of size at most 20.
• The maximum number of different words that can appear is 20000.
• The maximum number of words per day is 20000.
• Words of length less than four characters are considered of no interest.
• The number of days will be at most 1000.
• 1 ≤ N ≤ 20
OUTPUT
The list of N most frequent words during the last 7 days must be shown given a query. Words
must appear in decreasing order of frequency and in alphabetical order when equal frequency.
There must be shown all words whose counter of appearances is equal to the word
at position N. Even if the amount of words to be shown exceeds N.

SAMPLE INPUT
<text>
imagine you are in the hiring process of a company whose
main business is analyzing the information that appears
in the web
</text>
<text>
a simple test consists in writing a program for
maintaining up to date a set of trending topics
</text>
<text>
you will be hired depending on the efficiency of your solution
</text>
<top 5 />
<text>
they provide you with a file containing the text
corresponding to a highly active blog
</text>
<text>
the text is organized daily and you have to provide the
sorted list of the n most frequent words during last week
when asked
</text>
<text>
each input file contains one test case the text corresponding
to a day is delimited by tag text
</text>
<text>
the query of top n words can appear between texts corresponding
to two different days
</text>
<top 3 />
<text>
blah blah blah blah blah blah blah blah blah
please please please
</text>
<top 3 />
2
Problem IProblem I
Trending Topic
SAMPLE OUTPUT
<top 5>
analyzing 1
appears 1
business 1
company 1
consists 1
date 1
depending 1
efficiency 1
hired 1
hiring 1
imagine 1
information 1
main 1
maintaining 1
process 1
program 1
simple 1
solution 1
test 1
that 1
topics 1
trending 1
whose 1
will 1
writing 1
your 1
</top>
<top 3>
text 4
corresponding 3
file 2
provide 2
test 2
words 2
</top>
<top 3>
blah 9
text 4
corresponding 3
please 3
</top>

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <vector>using namespace std;typedef pair<int,int> pII;map<string,int> Hash;
vector<int> dy[11];
string rHash[20200];
int day_sum[11][20200];
char cache[30];
int now=9,pre=0,id=1;
int arr[20020],na;
string rss[20020];
bool vis[20020];void DEBUG(int x)
{int sz=dy[x].size();for(int i=0;i<sz;i++){cout<<"ID: "<<dy[x][i]<<" : "<<rHash[dy[x][i]]<<endl;cout<<"sum: "<<day_sum[x][dy[x][i]]<<endl;}
}struct RSP
{int times;string word;
}rsp[20020];bool cmpRSP(RSP a,RSP b)
{if(a.times!=b.times)return a.times>b.times;elsereturn a.word<b.word;
}void get_top(int now,int k)
{int sz=dy[now].size();na=0;int _7dayago=(now+3)%10;memset(vis,false,sizeof(vis));for(int i=0;i<sz;i++){if(vis[dy[now][i]]==false){arr[na++]=day_sum[now][dy[now][i]]-day_sum[_7dayago][dy[now][i]];vis[dy[now][i]]=true;}}sort(arr,arr+na);int sig=arr[max(0,na-k)];int rn=0;memset(vis,false,sizeof(vis));for(int i=0;i<sz;i++){int times=day_sum[now][dy[now][i]]-day_sum[_7dayago][dy[now][i]];if(times >= sig &&vis[dy[now][i]]==false){rsp[rn++]=(RSP){times,rHash[dy[now][i]]};vis[dy[now][i]]=true;}}sort(rsp,rsp+rn,cmpRSP);printf("<top %d>\n",k);for(int i=0;i<rn;i++){cout<<rsp[i].word<<" "<<rsp[i].times<<endl;}printf("</top>\n");
}int main()
{while(scanf("%s",cache)!=EOF){if(strcmp(cache,"<text>")==0){///read cachepre=now;now=(now+1)%10;dy[now]=dy[pre];memcpy(day_sum[now],day_sum[pre],sizeof(day_sum[0]));///7 day ago    ....while(scanf("%s",cache)){if(cache[0]=='<') break;if(strlen(cache)<4) continue;string word=cache;if(Hash[word]==0){rHash[id]=word;Hash[word]=id++;}int ID=Hash[word];if(day_sum[pre][ID]==0)dy[now].push_back(ID);day_sum[now][ID]++;}}else if(strcmp(cache,"<top")==0){int top;scanf("%d",&top); scanf("%s",cache);get_top(now,top);}}return 0;
}

SWERC13 Trending Topic相关推荐

  1. 如何在Docker上构建Node.js应用程序

    Docker has been the latest trending topic over the past couple of years and if you haven't been to s ...

  2. 考研英语图画类大作文

    文章目录: 一:开头段 1.话题引起 2.图画描述 3.图画总结(承上启下) 二:中间段 1.引出目的(主要问题.寓意是什么) 2.意义阐释(原因是什么 :解释.进行举例) 3.影响(正或负)[可不写 ...

  3. Hulu背后的故事:NLP在Hulu的研究与实践

    前言 "当你在凝视深渊的时候,深渊也在凝视着你."当你在看Hulu的时候,Hulu以及它背后的那些算法工程师们又在想些什么?不妨,就通过我加入Hulu以来的经历,一窥自然语言处理研 ...

  4. 外刊精读(丁晓钟)(上)

    外刊精读(丁晓钟)(上) The Guardian<卫报> Amazon profits surge as investment in faster shipping pays off R ...

  5. 日常计算机网络英语对话,社交网络用语的英文表达进入了我们的日常对话

    近些年"social media 社交媒体"在不断改变着我们的生活方式,成为生活中不可缺少的一部分,与此同时衍生的社交网络用语也悄悄地进入了我们的日常对话.当中很多用语的英文说法是 ...

  6. 20170814(三道题-DAG上DP 二分查找 map)

    题目 NYOJ_16 矩形嵌套 题意 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a 解决 DAG上的动态规划 1. 二元关系能够用图来建立 ...

  7. 英语流利说 第12天

    带着问题听讲解 Q1: "Chinese bots"该怎么理解? Q2: "煽风点火.火上浇油"用英文可以怎么说?fanned Q3: 你对这次事件有何看法?请 ...

  8. 图像处理-State of the Art

    https://github.com/BlinkDL/BlinkDL.github.io 目前常见图像任务的 State-of-the-Art 方法,从 Super-resolution 到 Capt ...

  9. 从CVPR 2013看计算机视觉的研究领域和趋势 [CVPR 2013] Three Trending Computer Vision Research Areas

    [CVPR 2013] Three Trending Computer Vision Research Areas As I walked through the large poster-fille ...

最新文章

  1. 2.27 18种定位方法总结
  2. 观察者模式 Observer
  3. CSS文件添加 @charset utf-8; 可能会引起样式在IE6下失效
  4. 04机器学习实战之朴素贝叶斯
  5. 数字图像处理 第四章 图像增强
  6. html内容封装为一个对象_技术赋能还是内容为王,哪一个才是短视频创作的关键?...
  7. mysql 增删改数据 dml 1207 0310
  8. php的验证码要gd库,PHP通过GD库实现验证码功能
  9. 怎样用代码方式退出IOS程序
  10. AMPL—快速了解,秒懂它。
  11. VMware ESXi 安装
  12. gsm手机影响计算机屏幕会怎么样,手机的辐射对孕妇的危害有多大
  13. 【随记】Dialog dismiss无法正常关闭问题
  14. 第十五届全国大学生智能汽车竞赛华南赛区获奖信息
  15. 学生们共被分为10个等级,包括学魔、学神、学霸、学痞、学弱^
  16. Linux下视频流媒体服务器搭建详解理论
  17. 真·电子二胡 (ESP32配合库乐队APP实现的电子制作)
  18. 宝藏动植物元素矢量图素材,速来收藏
  19. Unity之新版输入系统InputSystem如何自定义InputActions
  20. 云服务器测速脚本_服务器测速命令

热门文章

  1. php curl form-data,php – CURL POST multipart / form-data
  2. Android 侧滑菜单(抽屉)的使用总结
  3. 浅析英特尔QSV技术在FFmpeg中的具体实现与使用
  4. webots-Controller Programming
  5. android设备离线授权方案,adb-Android Studio-设备已连接但“离线”
  6. 概率论知识回顾(十五):变量函数的期望,期望的性质
  7. Debug版本下能运行而Release下不能运行的问题总结
  8. 电脑麦块java环境安装包下不上怎么办
  9. 经典复古调色lr预设
  10. 苹果WWDC2023:首款MR头显震撼发布,开发者泪洒现场,一文读懂全新产品及创新功能