[BZOJ]4419: [Shoi2013]发微博 set暴力
来源:互联网 发布:unity3d和虚幻4 比较 编辑:程序博客网 时间:2024/06/09 07:08
Description
刚开通的SH微博共有n个用户(1..n标号),在短短一个月的时间内,用户们活动频繁,共有m条按时间顺序的记录:
! x 表示用户x发了一条微博;
+ x y 表示用户x和用户y成为了好友
- x y 表示用户x和用户y解除了好友关系
当一个用户发微博的时候,所有他的好友(直接关系)都会看到他的消息。
假设最开始所有人之间都不是好友关系,记录也都是合法的(即+ x y时x和y一定不是好友,而- x y时x和y一定是好友)。
问这m条记录发生之后,每个用户分别看到了多少条消息。
题解:
对每个用户开一个set,存他的朋友有哪些,用a[x]表示x这个用户当前发的微博数,ans[x]表示x最后的答案,对于+操作,把x的集合中加进y,y的集合上加进x,ans[x]-=a[y],ans[y]-=a[x],-操作同理。最后扫一遍即可。
代码:
#include<cstdio>#include<cstring>#include<set>#include<iostream>#include<algorithm>using namespace std;const int maxn=200010;int n,m,a[maxn],ans[maxn];char op[3];set<int>s[maxn];int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { int x,y; scanf("%s%d",op,&x); if(op[0]=='!')a[x]++; else if(op[0]=='+') { scanf("%d",&y); s[x].insert(y); s[y].insert(x); ans[x]-=a[y]; ans[y]-=a[x]; } else { scanf("%d",&y); s[x].erase(y); s[y].erase(x); ans[x]+=a[y]; ans[y]+=a[x]; } } for(int j=1;j<=n;j++) for(set<int>::iterator i=s[j].begin();i!=s[j].end();i++) { ans[j]+=a[*i]; } for(int i=1;i<n;i++)printf("%d ",ans[i]); printf("%d\n",ans[n]);}
阅读全文
1 0
- [BZOJ]4419: [Shoi2013]发微博 set暴力
- 4419: [Shoi2013]发微博|暴力|set
- 【BZOJ 4419】[Shoi2013]发微博 单纯暴力
- 【BZOJ】4419: [Shoi2013]发微博
- bzoj 4419: [Shoi2013]发微博
- BZOJ 4419 [Shoi2013]发微博
- BZOJ 4419: [Shoi2013]发微博
- 4419: [Shoi2013]发微博 set
- bzoj 4419: [Shoi2013]发微博 乱搞
- bzoj 4419: [Shoi2013]发微博 (STL)
- 【BZOJ4419】[Shoi2013]发微博【set】
- BZOJ_P4419 [SHOI2013]发微博(STL+Set)
- 4419: [Shoi2013]发微博
- bzoj 4415: [Shoi2013]发牌
- bzoj 4415: [Shoi2013]发牌
- bzoj 4415: [Shoi2013]发牌
- [BZOJ 4416][Shoi2013]阶乘字符串
- bzoj 4417: [Shoi2013]超级跳马
- 算法第二周Add Two Numbers[medium]
- Struts2-01-数据访问
- [poj 1679] The Unique MST---(翻译:次小生成树)
- 2017年9月17日训练总结
- hello world!
- [BZOJ]4419: [Shoi2013]发微博 set暴力
- 使用servlet导出excel表
- 调戏源码之Spring MVC(三)
- 三个整数排列大小
- iOS开发-Protocol协议及委托代理(Delegate)传值
- [嵌入式Linux驱动]S5PV210的DHT11温湿度传感器Linux驱动
- pod头文件和pch文件路径问题
- 然后是几点
- ImageLoader图片异步加载详解