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 ...
 
随机推荐
- Windows系统的文件浏览器如何触发刷新
			
最近开发一个Drive程序,修改注册表添加System Folder Drive后需要通知已打开的每个文件浏览器刷新.最初选择获取对应窗体的句柄并发送WM_KEYDOWN.WM_KEYUP的VK_F5 ...
 - CMOS构成的常见电路
			
CMOS门电路 以MOS(Metal-Oxide Semiconductor)管作为开关元件的门电路称为MOS门电路.由于MOS型集成门电路具有制造工艺简单.集成度高.功耗小以及抗干扰能力强等优点,因 ...
 - 关于卸载vmware后如何删除VMware Network Adapter VMnet1虚拟网卡
			
默认情况下.我们在windows下安装了vmware虚拟机后,都会产生VMware Network Adapter VMnet1虚拟网卡 对于vmware虚拟网卡的管理,我们可以在vmware虚拟机软 ...
 - [APP] Android 开发笔记 003-使用Ant Release 打包与keystore加密说明
			
接上节 [APP] Android 开发笔记 002 5. 使用ant release 打包 1)制作 密钥文件 release.keystore (*.keystore) keytool -genk ...
 - CentOS 6 安装python3.6
			
参考博客:https://www.cnblogs.com/xiaodangshan/p/7197563.html 安装过程比较简单,需要注意,安装之后,为了不影响系统自带的python2.6版本,需要 ...
 - vim配置函数跳转(c/c++)
			
暂时草记一下,有时间好好整理 ctags 如果只是查看函数与变量是在哪里定义的,用ctags就可以了. ctrl+]跳到定义的地方,ctrl+t跳回来. 想要像IDE那样在旁边显示函数与变量列表,用t ...
 - python---不支持中文注释解决办法
			
很神奇的一件事儿,pycharm不支持中文注释,具体解决办法: #-*- coding: utf- -*- 具体使用:
 - python开发环境搭建(windows+python2.7.5+django1.5.4)【原创】
			
先插入一条广告,博主新开了一家淘宝店,经营自己纯手工做的发饰,新店开业,只为信誉!需要的亲们可以光顾一下!谢谢大家的支持!店名: 小鱼尼莫手工饰品店经营: 发饰.头花.发夹.耳环等(手工制作)网店: ...
 - python----并发编程之IO模型
			
一:IO模型介绍 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个 ...
 - Centos7搭建vsftp服务器
			
环境查看 安装vsftp软件 yum -y install vsftpd 修改配置文件/etc/vsftpd/vsftpd.conf (其余配置保持默认即可) anonymous_enable=NO ...