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. golang闭包,传统斐波那契

    package main import (    "fmt") func main() {    f := fibonacci()    for i := 0; i < 10 ...

  2. 关于c# winform使用FidderCore.dll 遇到的一些问题,请求支援

    小弟最近再研究winform用fidder抓取包的过程.开始都很顺利,并且成功开启了代理网络.同时手机也设置代理,并且手机可以上网,而且电脑也能抓到手机的请求. 但是遇到两个问题. 1.,这里的关闭代 ...

  3. .Net并行计算支持嵌套事务的方法

    问题背景 一年前,我们开始利用.Net 4.0的TPL(Task Parallel Library)并行计算技术对复杂计算的功能节点进行性能优化,这些复杂计算往往会包含大量对数据库的操作.在应用TPL ...

  4. python监听鼠标和键盘

    import PyHook3 def OnMouseEvent(event): print('MessageName:',event.MessageName) print('Message:',eve ...

  5. 【Hexo】deploy出错的解决方法

    .ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...

  6. web自动化的行为驱动

    1.新建一个features包,在新建一个steps包 2.新建一个register.features文件 #coding=utf-8Feature:Register User As a develo ...

  7. Pytorch基础(5)——批数据训练

    一.知识点: 相关包:torch.utils.data import torch import torch.utils.data as Data 包装数据类:TensorDataset [包装数据和目 ...

  8. 最小化安装CentOS-7-x86_64-Minimal-1511图文教程

    说明: 虚拟机产品:VMware® Workstation 12 Pro,版本:12.5.0 build-4352439 系统镜像:CentOS-7-x86_64-Minimal-1511.iso 操 ...

  9. Codeforces 902D/901B - GCD of Polynomials

    传送门:http://codeforces.com/contest/902/problem/D 本题是一个数学问题——多项式整除. 对于两个整数a.b,求最大公约数gcd(a,b)的辗转相除法的函数如 ...

  10. Spring Cloud系列(二) 介绍

    Spring Cloud系列(一) 介绍 Spring Cloud是基于Spring Boot实现的微服务架构开发工具.它为微服务架构中涉及的配置管理.服务治理.断路器.智能路由.微代理.控制总线.全 ...