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 ...
随机推荐
- Java多线程之并发包,并发队列
目录 1 并发包 1.1同步容器类 1.1.1Vector与ArrayList区别 1.1.2HasTable与HasMap 1.1.3 synchronizedMap 1.1.4 Concurren ...
- ADFS 4.0 证书更新
ADFS 4.0 证书更新 由于公网证书的过期,需要重新更新ADFS的服务通信证书: 证书要求: 带私钥 PFX格式 更换流程: 证书安装到 证书\计算机\个人,安装后点开证书能看到"你有一 ...
- spring aop中的propagation的7种配置
1.前言 在声明式的事务处理中,要配置一个切面,即一组方法,如 <tx:advice id="txAdvice" transaction-manager="txMa ...
- re模块3
#分组 () print(re.findall("(ad)/(vv)","adddad/vvdddddddddd")) print(re.findall(&qu ...
- Java线程——线程之间的数据共享
在 Java 传统线程机制中的共享数据方式,大致可以简单分两种情况: ➢ 多个线程行为一致,共同操作一个数据源.也就是每个线程执行的代码相同,可以使用同一个 Runnable 对象,这个 Runn ...
- Windows安装使用SonarQube7.4 对java项目进行代码质量扫描
我这里使用7.4因为使用JDK是1.8 其它版本看下依赖版本就好 1.下载7.4版本安装包 https://binaries.sonarsource.com/CommercialDistributio ...
- 吴裕雄--天生自然MySQL学习笔记:MySQL 函数
ASCII(s) 返回字符串 s 的第一个字符的 ASCII 码. SELECT ASCII(CustomerName) AS NumCodeOfFirstChar FROM Customers; C ...
- 18 11 07 pygame 继续使用
---恢复内容开始--- 1 给原来的游戏不定时 增加一些敌机 用到了pygame的定时器 定时器就是每隔一段时间 就进行一次相同的操作 2 pyagame 在捕获键盘操作有两种 1 ...
- 修复grub
进入命令行模式,#chroot /mnt/sysimage :切换根目录#grub2-install /dev/sda :安装grub2到第一硬盘#grub2-mkconfig -o /boot/gr ...
- 32. docker swarm 集群服务通信 之 RoutingMesh - internal 网络
1. 两个 service 是如何通信的 通过内置的 DNS 服务发现的功能 相互通信的 2. 创建一个 overlay 的 网络 docker network create -d overlay ...