当前位置:网站首页>OJ 1089 Spring Festival travel
OJ 1089 Spring Festival travel
2022-07-28 06:38:00 【JETECHO】
describe
Spring Festival transportation is coming , Relevant departments should count the flow of people during the Spring Festival transportation . There is a bus , Co stop N(1<N<1000000) A station ( The station number is 1,2,3,……), Then give M personal , Everyone from a Get on at the station , And then in b Get off at the station , Your task is to count the number of people on the bus when it stops at each stop . The number of people on the train includes those who get on and those who don't get off at this station , The number of people getting off at this station should not be recorded .
Input
The first line of each test instance is an integer N,(N <= 1000000). And a positive integer M(M<=1000000), Next M Each line includes 2 It's an integer a b(1 <= a < b <= N).
When N = 0, End of input .
Output
Each test instance outputs one line , Include N It's an integer , The first I The number represents that the bus stops at I The number of people on the train at a station .
sample input 1
3 2
1 2
2 3
3 3
1 2
1 3
2 3
0
sample output 1
1 1 0
2 2 0
For this problem, we can first use an array to store the status of each station , An array stores the car and an array stores the car , Then set a sum by 0, Then make sum Add the number of people getting on the train at each station and reduce the number of people getting off the train ,sum The value of is not initialized in the whole output , So if you don't get off the bus, you will be kept
#include <iostream>
#include <cstdio>
using namespace std;
int c[1000005],d[1000005];
int main()
{
int n,m;
while(cin>>n&&n)
{
cin>>m;
fill(c,c+n+1,0);
fill(d,d+n+1,0);
while(m--)
{
int x,y;
cin>>x>>y;
c[x]++;
d[y]++;
}
int sum=0;
for(int i=1;i<=n;i++)
{
sum=sum+c[i]-d[i];
if(i==1)
cout<<sum;
else
cout<<" "<<sum;
}
cout<<endl;
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
七夕送什么礼物好?小众又高级的产品礼物推荐
Leetcode 刷题日记 剑指 Offer II 048. 序列化与反序列化二叉树
【详解如何一步步实现三子棋】
What's a gift for girls on Chinese Valentine's day? Selfie online and thoughtful gift recommendation
2022年七夕礼物推荐!好看便宜又实用的礼物推荐
使用wampserver3.2.6时切换中文时造成启动失败
QT painting event - set background picture
execjs 调用
用c语言实现三子棋小游戏
OJ 1131 美丽数
OJ 1505 保险丝
2021-11-10
刷题记录----链表
[PTA----输出全排列]
2022-05-15 based on JWT token
C语言memcpy库函数与memmove的作用
到底什么是Hash?(量化交易机器人系统开发)
结构体、位段、联合体(共用体)的大小如何计算
QT implementation outputs relevant information to log file
2022年七夕送女朋友什么礼物好?实用且好看的礼物推荐



![[PTA----树的遍历]](/img/d8/260317b30d624f8e518f8758706ab9.png)



![OpenGL development environment configuration [vs2017] + frequently asked questions](/img/29/cefa8601310caf56ae9605cbf7fbbf.png)

