Box and Ball
题目描述
Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box xi, then he puts it into box yi.
Find the number of boxes that may contain the red ball after all operations are performed.
Constraints
2≤N≤105
1≤M≤105
1≤xi,yi≤N
xi≠yi
Just before the i-th operation is performed, box xi contains at least 1 ball.
输入
N M
x1 y1
:
xM yM
输出
样例输入
3 2
1 2
2 3
样例输出
2
提示
Just after the first operation, box 1 is empty, box 2 contains one red ball and one white ball, and box 3 contains one white ball.
Now, consider the second operation. If Snuke picks the red ball from box 2, the red ball will go into box 3. If he picks the white ball instead, the red ball will stay in box 2. Thus, the number of boxes that may contain the red ball after all operations, is 2.
这是我的代码。我的队友刚开始并没有先标记再遍历
#include <bits/stdc++.h> using namespace std;
struct data
{
int sum=;
int red=;
}s[];
int main()
{
ios::sync_with_stdio(false);
int n,m,i;
cin>>n>>m;
s[].sum=s[].red=;
for(i=;i<=n;i++) s[i].sum=;
int x,y,ans=;
while(m--){
cin>>x>>y;
if(s[x].red==&&s[x].sum==){
s[y].red=;
s[x].sum=s[x].red=;
s[y].sum++;
}
else if(s[x].red==&&s[x].sum!=){
s[y].sum++;
s[x].sum--;
}
else if(s[x].red==&&s[x].sum>){
s[x].sum--;
s[y].red=;
s[y].sum++;
}
}
for(i=;i<=n;i++){
if(s[i].red==) ans++;
}
cout<<ans<<endl;
return ;
}
Box and Ball的更多相关文章
- box2d中的物理世界
box2d中的物理世界,即b2World类就是一个包含了各种物体(body,物理体,或者叫刚体),固定附着物(fixture,形状与物理体的绑定物)以及各种约束体(比如关节),并使其在当中完成各种交互 ...
- 用HTML5+原生js实现的推箱子游戏
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- AtCoder Grand Contest 002
AtCoder Grand Contest 002 A - Range Product 翻译 告诉你\(a,b\),求\(\prod_{i=a}^b i\)是正数还是负数还是零. 题解 什么鬼玩意. ...
- RE:从零开始的AGC被虐(到)生活(不能自理)
RE:从零开始的AGC被虐(到)生活(不能自理) 「一直注视着你,似近似远,总是触碰不到.」 --来自风平浪静的明天 AtCoder Grand Contest 001 B: Mysterious L ...
- AtCoder AGC #2 Virtual Participation
在知乎上听zzx大佬说AGC练智商...于是试了一下 A.Range Product 给$a$,$b$,求$\prod^{b}_{i=a}i$是正数,负数还是$0$ ...不写了 B.Box and ...
- Atcoder/Topcoder 口胡记录
Atcoder/Topcoder 理论 AC Atcoder的❌游戏示范 兴致勃勃地打开一场 AGC 看 A 题,先 WA 一发,然后花了一年时间 Fix. 看 B 题,啥玩意?这能求? 睡觉觉. e ...
- A*G`C002
AGC002 A Range Product 不会,弃疗了/kk https://agc002.contest.atcoder.jp/submissions/7908938 B Box and Bal ...
- 【AtCoder】AGC002
AGC002 A - Range Product #include <bits/stdc++.h> #define fi first #define se second #define p ...
- AGC002[BCDEF]题解
F是计数于是就做(kan ti jie)了= = B - Box and Ball 模拟一下 每个盒子开一个d表示有的球数 可能存在红球的打个标记 传递一下就行了 #include<cstdio ...
随机推荐
- 使用html画爱心
<!DOCTYPE html"> <html> <head> <meta http-equiv="Content-Type" c ...
- 直击JDD | 共建智能新城 京东云让城市生活变得简单美好
技术快速革新,创新持续激发.在"智能+"时代,云计算.大数据.5G等新技术,已成为社会生产方式变革.创新人类生活空间的重要力量--11月19日,JDD-2019京东全球科技探索者大 ...
- STM32F407的Modbus做为主站与从站通讯
在调试STM32F407的串口Modbus通讯之前,也使用过Modbus通讯,只不过都是在PLC或则昆仑通态的触摸屏上使用直接调用现成的库里面的模块,驱动就可以,相对于STM32来,使用PLC库里面的 ...
- Thread--停止线程
参考:http://blog.sina.com.cn/s/blog_6ca570ed01016mti.html Thread.interrupt()方法不会中断一个正在运行的线程.它的作用是,在线程受 ...
- 使用cropper插件裁剪并上传图片(Spring mvc)
cropper是一款使用简单且功能强大的图片剪裁jQuery插件.该图片剪裁插件支持图片放大缩小,支持图片旋转,支持触摸屏设备,支持canvas,并且支持跨浏览器使用. cropper有两种方式上传截 ...
- 系统学习python第三天学习笔记
day02补充 运算符补充 in value = "我是中国人" # 判断'中国'是否在value所代指的字符串中. "中国"是否是value所代指的字符串的子 ...
- ASP.NET ZERO 学习 JTable的使用
View信息: @using Abp.Web.Mvc.Extensions @using MedicalSystem.Authorization @using MedicalSystem.Web.Na ...
- Maven--优化依赖
Maven 会自动解析所有项目的直接依赖和传递依赖,并且根据规则正确判断每个依赖的范围,对于一些依赖冲突,也能进行调节,以确保任何一个构件只有唯一的版本在依赖中存在.在这些工作之后,最后得到的那些依赖 ...
- 自由职业平台Upwork申请上市,能给国内猪八戒网带来什么启示?
当下,在互联网的全面渗入下已经对整个社会的运行机制.大众的生活产生了前所未有的影响.尤其是在工作方面,更是衍生出诸多新兴职业.如,主播.水军.新媒体运营.自媒体人等.值得注意的是,这些职业绝大部分都有 ...
- 洛谷 P3808 【模板】AC自动机(简单版)
传送门:https://www.luogu.org/problem/P3808 题解:是一个AC自动机的裸题了,注释加在代码里面了 #include<bits/stdc++.h> usin ...