PAT 1076 Forwards on Weibo[BFS][一般]
1076 Forwards on Weibo (30)(30 分)
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers can view and forward his/her post, which can then be forwarded again by their followers. Now given a social network, you are supposed to calculate the maximum potential amount of forwards for any specific user, assuming that only L levels of indirect followers are counted.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=1000), the number of users; and L (<=6), the number of levels of indirect followers that are counted. Hence it is assumed that all the users are numbered from 1 to N. Then N lines follow, each in the format:
M[i] user_list[i]
where M[i] (<=100) is the total number of people that user[i] follows; and user_list[i] is a list of the M[i] users that are followed by user[i]. It is guaranteed that no one can follow oneself. All the numbers are separated by a space.
Then finally a positive K is given, followed by K UserID's for query.
Output Specification:
For each UserID, you are supposed to print in one line the maximum potential amount of forwards this user can triger, assuming that everyone who can view the initial post will forward it once, and that only L levels of indirect followers are counted.
Sample Input:
7 3
3 2 3 4
0
2 5 6
2 3 1
2 3 4
1 4
1 5
2 2 6
Sample Output:
4
5
题目大意:给出一个关注网络,检测在L内,一个用户发帖,最多有多少个转发量,像是宽度优先遍历,是有向图。
#include <iostream>
#include <algorithm>
#include <vector>
#include<queue>
using namespace std;
vector<int> user[];
int vis[];
int main() {
int n,L;
queue<int> qu;
cin>>n>>L;
int k,temp;
for(int i=;i<=n;i++){
cin>>k;
for(int j=;j<k;j++){
cin>>temp;
user[temp].push_back(i);
}
}
cin>>k;
int ct=,level=,num;
for(int i=;i<k;i++){
fill(vis,vis+n+,);//开心到哭泣,这里错了,导致过不去,因为编号是从1-n,所以就导致了最后一个点被赋值为1之后,一直为1.
cin>>temp;
ct=,level=;
while(!qu.empty())qu.pop();
qu.push(temp);
vis[temp]=;
qu.push(-);
while(level!=L){
while(!qu.empty()){
num=qu.front();
qu.pop();
if(num==-){
qu.push(-);
break;
}
for(int j=;j<user[num].size();j++){
if(!vis[user[num][j]]){
qu.push(user[num][j]);//将其放入
vis[user[num][j]]=;
ct++;
}
}
}
level++;
}
cout<<ct;
if(i!=k-)cout<<'\n';
}
return ;
}
我的AC代码,一般出现段错误就是数组长度设置的太小了,反正这次是这样。
1.还有一个困扰我的地方,“and that only L levels of indirect followers are counted.”,这里其实是很简单,并不是第一层的不算,所有的能转发的人都算在内。
PAT 1076 Forwards on Weibo[BFS][一般]的更多相关文章
- PAT 1076. Forwards on Weibo (30)
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may ...
- PAT 1076 Forwards on Weibo
#include <cstdio> #include <cstdlib> #include <vector> #include <queue> #inc ...
- PAT 甲级 1076 Forwards on Weibo (30分)(bfs较简单)
1076 Forwards on Weibo (30分) Weibo is known as the Chinese version of Twitter. One user on Weibo m ...
- PAT甲级1076. Forwards on Weibo
PAT甲级1076. Forwards on Weibo 题意: 微博被称为中文版的Twitter.微博上的一位用户可能会有很多关注者,也可能会跟随许多其他用户.因此,社会网络与追随者的关系形成.当用 ...
- 1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise
题目信息 1076. Forwards on Weibo (30) 时间限制3000 ms 内存限制65536 kB 代码长度限制16000 B Weibo is known as the Chine ...
- 1076 Forwards on Weibo (30 分)
1076 Forwards on Weibo (30 分) Weibo is known as the Chinese version of Twitter. One user on Weibo ma ...
- PAT Advanced 1076 Forwards on Weibo (30) [图的遍历,BFS,DFS]
题目 Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and ...
- PAT甲题题解-1076. Forwards on Weibo (30)-BFS
题目大意:给出每个用户id关注的人,和转发最多的层数L,求一个id发了条微博最多会有多少个人转发,每个人只考虑转发一次.用BFS,同时每个节点要记录下所在的层数,由于只能转发一次,所以每个节点要用vi ...
- 1076. Forwards on Weibo (30) - 记录层的BFS改进
题目如下: Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, a ...
随机推荐
- 《征服C指针》读书笔记
本文同时发布在我的个人博客上,欢迎访问~ www.seekingdream.cn 在读完K&R之后,对C的认识就是指针.数组.网上的人们对指针也有些“敬而远之”的感觉.最近从同学处淘得< ...
- 这些JavaScript编程黑科技
1.单行写一个评级组件 "★★★★★☆☆☆☆☆".slice(5 - rate, 10 - rate);定义一个变量rate是1到5的值,然后执行上面代码,看图 才发现插件什么的都 ...
- C# XtraGrid的行指示器(RowIndicator)行号以及图标设置
以下是几种对Xtragrid的行指示器的几种操作方法,在实际场景当中,很多都需要用到,直接上效果图和源码 一.基本篇—设置表头行号 1.效果图 2.实现方法 需要对XtraGrid事件CustomDr ...
- sencha touch 2.2.1 自定义彩色图标按钮(button+ico)
sencha touch 2.2.1 这个版本使用了新的按钮模式,不过他只提供了少部分的按钮样式.我们可以加一些自定义的ico样式 新加ico样式lower .x-button .x-button-i ...
- 栈和队列的基础算法学习(EPI)
今天学习的时间虽然挺多的,但是总觉效率不高.其实今天没有按照计划进行EPI题目的浏览,白天去看了其他的书籍.准备找工作可能需要的状态是一定量经典的书,偶尔温习才可.书是看不完的,知识点也是固定的.所以 ...
- linux下模拟CPU占用100%小程序
在做一个测试时,需要模拟服务器CPU占用满的情况,在查阅相关资料后,发现网上程序不太好用, 原文在这:http://www.2cto.com/os/201304/202068.html 优化后如下: ...
- iOS - 开发代码部分规范
1. 关于命名 1.1 统一要求 含义清楚,尽量做到不需要注释也能了解其作用,若做不到,就加注释 使用全称,不适用缩写 1.2 类的命名 大驼峰式命名:每个单词的首字母都采用大写字母 例子:MFHom ...
- Kafka在Linux上安装部署及样例测试
Kafka是一个分布式的.可分区的.可复制的消息系统.它提供了普通消息系统的功能,但具有自己独特的设计.这个独特的设计是什么样的呢 介绍 Kafka是一个分布式的.可分区的.可复制的消息系统.它提供了 ...
- HOJ-1005 Fast Food(动态规划)
Fast Food My Tags (Edit) Source : Unknown Time limit : 3 sec Memory limit : 32 M Submitted : 3777, A ...
- octomap的简介
装载自高翔博士的博客:https://www.cnblogs.com/gaoxiang12/p/5041142.html 什么是octomap? RGBD SLAM的目的有两个:估计机器人的轨迹,并建 ...