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 ...
随机推荐
- SVN —— 如何设置代理
如果在使用SVN下载外网的资源时,出现这样的提示:No such host is known. 或者 不知道这样的主机,可能是机器网络的问题. 如果浏览器能够正常访问外网,那应该是网络设置了代理的问题 ...
- 【前端安全】JavaScript防http劫持与XSS (转)
作为前端,一直以来都知道HTTP劫持与XSS跨站脚本(Cross-site scripting).CSRF跨站请求伪造(Cross-site request forgery).但是一直都没有深入研究过 ...
- LeetCode 46 Permutations(全排列问题)
题目链接:https://leetcode.com/problems/permutations/?tab=Description Problem:给出一个数组(数组中的元素均不相同),求出这个数组 ...
- 根据json对象的值替换json数组里的值
功能: var fruitArry=[{name:'durian'},{name:'peach'},{name:'banana'},{name:'pitaya'},{name:'apple'},{na ...
- Windows Phone Bing lock screen doesn't change解决方法
之前一直用的Lumia 925,Bing lock screen每天都会更换.这几天换了Lumia 930,同步了账号相关的设置,发现Bing lock screen不再每天更换.尝试重启.使用cel ...
- ConfluenceRemoteUserAuth
配置confluence使用httpHeader的方式进行登录(目标版本:atlassian-confluence-6.3.3) 前提是已经安装好了Confluence,并且前端使用apache或者n ...
- C# 队列(Queue)解决简单并发
日志例子: private static Queue<string> m_Message = new Queue<string>(); private static bool ...
- [APP] Android 开发笔记 001-环境搭建与命令行创建项目
1. 安装JDK,SDK JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html Android SDK http ...
- iOS - 处理计算精度要求很高的数据,floatValue,doubleValue等计算不精确问题
.问题描述:服务器返回的double类型9...94的数字时 .之前处理方式是 :(从内存.cpu计算来说double都是比较合适的,一般情况下都用double) goodsPrice.floatVa ...
- spring配置多视图解析器
最近做一个小项目(移动端),自己搭了个简单的SSM框架(spring + spring MVC + Mybitis),展示层本来选用的是jsp,各方便都已经搭建好,结果发现有些页面需要用到H5的一些功 ...