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多线程之volatile关键字
public class ThreadVolatile extends Thread { public boolean flag=true; @Override public void run() { ...
- .NET CORE 热更新,否则提示DLL文件在使用中
1.创建空目录,取名updatesite,里面放置app_ffline.htm文件,网站更新中访问使用,内容随意 2.updatesite目录下面创建Release目录,用于放置更新的dll文件 3. ...
- offset系列、client系列、scroll系列
offset系列.client系列 <style> .testDOM { width: 200px; height: 200px; background-color: #2de; pa ...
- 干货 | MySQL数据库安全之审计
干货 | MySQL数据库安全之审计 原创: 李勇 京东云开发者社区 今天 每家公司都希望业务高速增长,最好能出几个爆款产品或者爆款业务,从而带动公司营收高速攀升.但站在数据库管理员的角度,这却是实 ...
- 寒假day15
今天完成了毕设的人才动态模块,同时刷了计算机网络的相关面试题
- App的布局管理
今天学习了布局管理器,格局自己的学习内容和课程,我主要学习了两种管理布局方式 一:LinearLayout线性布局 线性布局是指布局里面的内容成线性排列,有两种排列方式,横向排列和纵向排列,而排列方式 ...
- Ctrl +c 脚本中
#!/bin/bashsar -n DEV 1 111111111111111 >>1.txt & #实时网卡流量数据 sleep 3 && kill -2 ...
- python中selenium自动化常用关键字
一:定位八种方法 例如: 二:常见的webdriver方法 1.浏览器相关:(打开浏览器先导入webdriver模块) (1)set_window_size(480,800)调整浏览器宽高大小 (2) ...
- 201312-1 出现次数最多的数Java
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Scanner; ...
- java内存区域与内存溢出异常(2)
3.本地方法栈 本地方法栈与虚拟机栈作用相同,不同的是虚拟机栈为java方法服务,本地方法栈为native方法服务,本地方法栈会抛出StackOverFlowError和OutOfMemoryErro ...