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;
else
return 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 cache
pre=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. UVA 12686 Trending Topic

    Trending Topic Time limit: 1.000 seconds Imagine you are in the hiring process for a company whose p ...

  2. USER STORIES AND USE CASES - DON’T USE BOTH

    We’re in Orlando for a working session as part of the Core Team building BABOK V3 and over dinner th ...

  3. [转载]Three Trending Computer Vision Research Areas, 从CVPR看接下来几年的CV的发展趋势

    As I walked through the large poster-filled hall at CVPR 2013, I asked myself, “Quo vadis Computer V ...

  4. Kafka 如何读取offset topic内容 (__consumer_offsets)

    众所周知,由于Zookeeper并不适合大批量的频繁写入操作,新版Kafka已推荐将consumer的位移信息保存在Kafka内部的topic中,即__consumer_offsets topic,并 ...

  5. Kafka如何创建topic?

    Kafka创建topic命令很简单,一条命令足矣:bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-facto ...

  6. Kafka0.8.2.1删除topic逻辑

    前提条件: 在启动broker时候开启删除topic的开关,即在server.properties中添加:  delete.topic.enable=true 命令: bin/kafka-topics ...

  7. [bigdata] kafka基本命令 -- 迁移topic partition到指定的broker

    版本 0.9.2 创建topic bin/kafka-topics.sh --create --topic topic_name --partition 6 --replication-factor ...

  8. Kafka vs RocketMQ——多Topic对性能稳定性的影响-转自阿里中间件

    引言 上期我们对比了RocketMQ和Kafka在多Topic场景下,收发消息的对比测试,RocketMQ表现稳定,而Kafka的TPS在64个Topic时可以保持13万,到了128个Topic就跌至 ...

  9. Kafka vs RocketMQ—— Topic数量对单机性能的影响-转自阿里中间件

    引言 上一期我们对比了三类消息产品(Kafka.RabbitMQ.RocketMQ)单纯发送小消息的性能,受到了程序猿们的广泛关注,其中大家对这种单纯的发送场景感到并不过瘾,因为没有任何一个网站的业务 ...

随机推荐

  1. ROS-导航功能-Gazebo

    前言:仿真的整体思路,先启动仿真环境,再启动导航功能. 前提:已下载并编译了相关功能包集,如还未下载,可通过git下载:https://github.com/huchunxu/ros_explorin ...

  2. S - New Year Transportation

    Problem description New Year is coming in Line World! In this world, there are n cells numbered by i ...

  3. A - High School: Become Human

    Problem description Year 2118. Androids are in mass production for decades now, and they do all the ...

  4. Eclipse 添加本地 SVN插件以及运行项目的流程

    去网上下载SVN插件包.里面包含文件如图: 把features和plugins文件夹里面的东西全部复制粘贴到eclipse安装目录下的features和plugins文件夹中就行.然后重启eclips ...

  5. 5.26 Quartz任务调度图解

  6. Linux系统下通过命令行对mysql数据进行备份和还原

    一.备份 1.进入mysql目录 cd /var/lib/mysql (进入mysql目录,根据安装情况会有差别) 2.备份 mysqldump -u root -p密码 数据库名 数据表名 > ...

  7. JAVA;使用java.awt.Image的不稳定性

    在使用awt的image时候,不是能时时获取到图像的宽和高, GetWidth()函数偶尔得到的值为-1,暂时没有找到解决方法. 代码: public class picture extends JF ...

  8. Unicode转换为UTF-8过程Demo

    碎碎念:这几天在学习Python对Unicode的支持 上学的时候,计算机基础课上总能听到老师讲什么字节,字符,Unicode,UTF-8吧啦吧啦一堆,反正我是只记住了名字,至于具体这些名字所表达的含 ...

  9. kafkaAPI

    使用方法见官网API介绍: https://kafka.apache.org/22/javadoc/index.html?org/apache/kafka/clients/consumer/Kafka ...

  10. BPM结束任务

    var pi = tw.system.findProcessInstanceByID("158");for(var i=0; i<pi.tasks.length; i++) ...