1076. Forwards on Weibo (30)

从零构建:如何用MATLAB打造你的第一个Stewart平台运动学仿真器 本文详细介绍了如何使用MATLAB从零构建一个六自由度Stewart平台运动学仿真器,涵盖基础理论、环境配置、运动学建模、动态轨迹规划和实时可视化实现。通过MATLAB的Robotics System Toolbox和Simulink等工具,读者可以掌握六自由度Stewart平台的逆运动学求解、正运动学求解及仿真系统集成,适用于飞行模拟器和精密定位等应用场景。 阅读详情

1076. Forwards on Weibo (30)

时间限制
3000 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

这题并不难,图的限制深度的BFS。重要的是邻接表的表示方法,本题

使用 vector a[1005] 来表示图,十分方便。

因为给的信息是用户i  follow了谁,而我们要看某个用户的微博可以被谁看,所以用邻接表存的时候反顾来存,并且是单向的

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
vector<int> G[1005];
int vis[1005];
int n,level;
int bfs(int a){
    memset(vis,0,sizeof(vis));
    int first = 0,last = 1,newlevel = 0,cnt = 1;
    //这几个变量特别解释一下,first和last是判断这一层是否输出完,因为第一个传进来的是用户本身不能算,所以newlevel从0开始,first从0开始,
    //last和cnt从1开始是为了过滤去开始的点即用户本身,便于循环,最后只需要减去1即可
    queue<int> q;
    q.push(a);
    vis[a] = 1;
    while(!q.empty()){
        int s = q.front();
        q.pop();
        first++;//每次取出一个++,包含了用户本身
        for(int i = 0; i < G[s].size(); i++){
            if(!vis[G[s][i]]){
                vis[G[s][i]] = 1;
                cnt++;//计算总数,同时得到了加上这一层后的总数
                q.push(G[s][i]);
            }
        }
        if(first == last){
            last = cnt;
            newlevel++;
        }
        if(newlevel == level){
            return cnt-1;
        }
    }
    return cnt-1;
}
int main(){
    cin >> n >> level;
    for(int i = 1; i <= n; i++){
        int m;
        cin >> m;
        while(m--){
            int t;
            cin >> t;
            G[t].push_back(i);
        }
    }
    int k;
    cin >> k;
    while(k--){
        int user;
        cin >> user;
        cout << bfs(user) << endl;
    }
    return 0;
}



多目标跟踪中使用trackeval评估dancetrack运行结果 trackeval使用 阅读详情

相关推荐

数学不好是原罪——高等数学笔记(汇总版)

这是本人之前考研的高数手写笔记,工科学硕数一考了146(满分150),笔记有一定参考价值,欢迎大家收藏借鉴。

xuuyann 5万+

1076 Forwards on Weibo (30分)

1 题目 1076 Forwards on Weibo (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...

韩江雪de 小屋 544

分享一下使用Xilinx FPGA驱动MIPI DSI LCD屏的心路历程

分享一下调试用Xilinx FPGA驱动MIPI DSI LCD屏的心路历程,看到的朋友们,可以避免继续踩坑。

haoxingheng的专栏 5010

PAT_甲级_1076 Forwards on Weibo (30point(s)) (C++)【BFS/微博扩散】

1,题目描述 2,思路 3,AC代码 4,解题过程 第一搏 一看,这不就是有向图的DFS遍历吗?看我分分钟KO。。。

&再见萤火虫&的博客 333

深度学习动画实战:用MotorNerve系统5步实现自然角色交互

本文详细介绍了如何利用腾讯游戏的MotorNerve系统,通过深度学习技术5步实现自然角色动画交互。从环境搭建、基础运动控制到交互过渡和行走转向优化,该系统能显著提升游戏动画制作效率,尤其适合中小团队替代昂贵的动捕方案。重点解析了骨骼动画配置、PFNN控制器使用及Blender工作流集成等核心技术。

book8的博客 685

Node-RED教程(二):Node-RED的面板的操作

Node-RED系列(二):Node-RED的面板的操作 要使用Node-RED去搭建一个物联网平台,链接设备,设备通信,就必须要先熟悉Node-RED的这种面板,对于一个新的项目,在动手做之前一点想对这个的技术的文档有足够的了解做起来才能游刃有余。本期我给大家介绍一下Node-RED的各种面板,熟悉这些面板后,在后续的搭建Iot服务中,会举重若轻,同时该系列的文档,难度会逐步加深,知道了本章解释的名称后对后续文章的理解有很大帮助。 面板1:默认节点选项列表 安装Node-RED后默认的节点分为这5大类

知无涯 1万+

PAT-1076. Forwards on Weibo (30)

消失了好久。。我又回来了...

very_caiing 1639

Python 爬虫实战:爬虫与 ECharts 结合 —— 前端可视化展示

本文介绍了爬虫技术与ECharts可视化结合的完整实现流程。首先使用Python爬取京东商品数据(价格、评价数等),通过BeautifulSoup解析和pandas处理转换为JSON格式。然后构建前端页面,利用ECharts实现价格分布柱状图、价格-评价数散点图和店铺占比饼图三种可视化效果。文章详细解析了爬虫数据提取、格式转换和前端图表配置等关键技术点,并提供了完整的代码示例。最后提出了基于API接口、数据库存储等扩展方向,为数据采集到可视化展示提供了完整的解决方案。

2503_91057718的博客 630

1076 Forwards on Weibo (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 ...

qq_39339575的博客 635

Spring AI 实战:第七章、Spring AI Advisor机制之记忆大师

从金鱼到最强大脑通过 Spring AI 的记忆功能,我们成功让 AI:记住了用户身份实现了多用户隔离做到了持久化存储最终效果用户:“和上次一样” → AI 秒懂用户:“你知道我的名字吗?” → AI:“当然,张三!AI的进化路线🐟金鱼脑 →🧠最强大脑 →🏛️记忆宫殿管理员。

liaokailin的专栏 1516

使用 MATLAB/Simulink + Communications Toolbox + 5G Toolbox,构建一个2×2 MIMO-OFDM通信系统

本文通过Simulink+CommunicationsToolbox构建2×2 MIMO-OFDM通信系统,重点实现信道均衡滤波器(ZF与MMSE)的设计与应用。详细介绍了系统架构、建模步骤(包括信道估计、均衡器实现)和仿真场景设计,通过BER、星座图和EVM对比分析验证了MMSE均衡器在抑制噪声和信号恢复方面的优势。文章总结了MIMO均衡的核心原理与实践经验,并提出了扩展至大规模MIMO、深度学习均衡器等优化方向,为无线通信系统设计提供实用指导。

amy_mhd的博客 125

1076 Forwards on Weibo (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...

大山喵写博客的地方 634

OSG第三方库编译之二十一:minizip编译(Windows、Linux、Macos环境下编译)

OSG编译;第三方库;跨平台编译;minizip编译(Windows、Linux、Macos环境下编译)

LuckyHanMo的博客 2619

PAT (Advanced Level) 1076. Forwards on Weibo (30) 微博转发 BFS

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

兔子哥哥的博客 522

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

1076 Forwards on Weibo (30分) BFS

文章目录问题解决方法题目大意解题思路BFS模板 问题 1076 Forwards on Weibo (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 so...

weixin_43725617的博客 319

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

1076 Forwards on Weibo (30分)

1076Forwards on Weibo(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 wit...

pan_xi_yi的博客 253

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

PAT 1076 Forwards on Weibo (30分)

原题链接:1076 Forwards on Weibo (30分) 关键词:BFS模板题、图 题目大意: 一个人发微博,可能会被关注他的人转发,现在给定一个微博关注关系图和最大转发的层数,问你最大转发数是多少。

cwtnice的博客 217

1076 Forwards on Weibo (30 分)

1076Forwards on Weibo(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 wi...

ZXX_1999的博客 199

1076 Forwards on Weibo (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 ...

SourDumplings的博客 221

1076 Forwards on Weibo (30)

【代码】1076 Forwards on Weibo (30)

2401_88085478的博客 599

PAT甲级 1076 Forwards on Weibo(30)

PAT甲级真题1076 Forwards on Weibo详解附AC代码

2301_79601095的博客 1216
上一篇: 1099. Build A Binary Search Tree (30)
下一篇: 1078. Hashing (25)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值