Codeforces 401B Sereja and Contests【水题】
2016-11-08 20:56
387 查看
B. Sereja and Contests
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: Div1 (for advanced coders) and
Div2 (for beginner coders). Two rounds,
Div1 and Div2, can go simultaneously, (Div1 round cannot be held without
Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round.
The identifiers of rounds that are run simultaneously are different by one, also the identifier of the
Div1 round is always greater.
Sereja is a beginner coder, so he can take part only in rounds of
Div2 type. At the moment he is taking part in a
Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly
k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds
he missed.
Sereja is wondering: what minimum and what maximum number of
Div2 rounds could he have missed? Help him find these two numbers.
Input
The first line contains two integers: x
(1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and
k (0 ≤ k < 4000) — the number of rounds he took part in.
Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1
num2
num1" (where
num2 is the identifier of this
Div2 round, num1 is the identifier of the
Div1 round). It is guaranteed that
num1 - num2 = 1. If Sereja took part in a usual
Div2 round, then the corresponding line looks like: "2
num" (where num is the identifier of this
Div2 round). It is guaranteed that the identifiers of all given rounds are less than
x.
Output
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
Examples
Input
Output
Input
Output
Input
Output
Note
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual
Div2 round and the round with identifier
6 will be synchronous with the Div1 round.
The maximum number of rounds equals 3. In this case all unused identifiers belong to usual
Div2 rounds.
题目大意:
已知有Div.1,和Div.2区分度的比赛,如果div1和div2比赛同时在一轮比赛中出现,div1的比赛编号保证比div2的编号大1.
一共有X编号,其中有K个已知参加了的比赛,其中K行如果是:
1 num1,num2,就表示这一场比赛div1div2是同时都有的,而且主人公只能参加div2.
2 num1,表示这一场比赛只有div2。
没有出现过的编号就是不知道的比赛,主人公想知道,他最少错过了多少场div2的比赛,最多错过了多少场div2的比赛。
思路:
1、很明显,最多错过的场数,就是从1-x-1中没有出现过的编号。
2、最少错过的场数,如果有连着两个编号都没有出现过,那么此时将这两个编号弄成一轮比赛(div1,div2同时在一轮中)即可。
Ac代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int vis[4500];
int main()
{
int x,k;
while(~scanf("%d%d",&x,&k))
{
memset(vis,0,sizeof(vis));
for(int i=0;i<k;i++)
{
int tmp;
scanf("%d",&tmp);
if(tmp==2)
{
int y;
scanf("%d",&y);
vis[y]=1;
}
else
{
int y,yy;
scanf("%d%d",&y,&yy);
vis[y]=1;
vis[yy]=1;
}
}
int minn=0;
int maxn=0;
for(int i=1;i<x;i++)
{
if(vis[i]==0)maxn++;
}
minn=maxn;
for(int i=1;i<x;i++)
{
if(vis[i]==0&&vis[i+1]==0&&i+1<x)
{
vis[i]=1;
vis[i+1]=1;
minn--;
}
}
printf("%d %d\n",minn,maxn);
}
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: Div1 (for advanced coders) and
Div2 (for beginner coders). Two rounds,
Div1 and Div2, can go simultaneously, (Div1 round cannot be held without
Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round.
The identifiers of rounds that are run simultaneously are different by one, also the identifier of the
Div1 round is always greater.
Sereja is a beginner coder, so he can take part only in rounds of
Div2 type. At the moment he is taking part in a
Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly
k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds
he missed.
Sereja is wondering: what minimum and what maximum number of
Div2 rounds could he have missed? Help him find these two numbers.
Input
The first line contains two integers: x
(1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and
k (0 ≤ k < 4000) — the number of rounds he took part in.
Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1
num2
num1" (where
num2 is the identifier of this
Div2 round, num1 is the identifier of the
Div1 round). It is guaranteed that
num1 - num2 = 1. If Sereja took part in a usual
Div2 round, then the corresponding line looks like: "2
num" (where num is the identifier of this
Div2 round). It is guaranteed that the identifiers of all given rounds are less than
x.
Output
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
Examples
Input
3 2 2 1 2 2
Output
0 0
Input
9 3 1 2 3 2 8 1 4 5
Output
2 3
Input
10 0
Output
5 9
Note
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual
Div2 round and the round with identifier
6 will be synchronous with the Div1 round.
The maximum number of rounds equals 3. In this case all unused identifiers belong to usual
Div2 rounds.
题目大意:
已知有Div.1,和Div.2区分度的比赛,如果div1和div2比赛同时在一轮比赛中出现,div1的比赛编号保证比div2的编号大1.
一共有X编号,其中有K个已知参加了的比赛,其中K行如果是:
1 num1,num2,就表示这一场比赛div1div2是同时都有的,而且主人公只能参加div2.
2 num1,表示这一场比赛只有div2。
没有出现过的编号就是不知道的比赛,主人公想知道,他最少错过了多少场div2的比赛,最多错过了多少场div2的比赛。
思路:
1、很明显,最多错过的场数,就是从1-x-1中没有出现过的编号。
2、最少错过的场数,如果有连着两个编号都没有出现过,那么此时将这两个编号弄成一轮比赛(div1,div2同时在一轮中)即可。
Ac代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int vis[4500];
int main()
{
int x,k;
while(~scanf("%d%d",&x,&k))
{
memset(vis,0,sizeof(vis));
for(int i=0;i<k;i++)
{
int tmp;
scanf("%d",&tmp);
if(tmp==2)
{
int y;
scanf("%d",&y);
vis[y]=1;
}
else
{
int y,yy;
scanf("%d%d",&y,&yy);
vis[y]=1;
vis[yy]=1;
}
}
int minn=0;
int maxn=0;
for(int i=1;i<x;i++)
{
if(vis[i]==0)maxn++;
}
minn=maxn;
for(int i=1;i<x;i++)
{
if(vis[i]==0&&vis[i+1]==0&&i+1<x)
{
vis[i]=1;
vis[i+1]=1;
minn--;
}
}
printf("%d %d\n",minn,maxn);
}
}
相关文章推荐
- Codeforces 835A Key races (水题)
- codeforces----2017 Hackatari Codeathon(A 暴力搜索 G概率)(水题DEH)
- CodeForces - 813C(最短路径水题)
- Codeforces-----140A---New Year Table---数学水题
- CodeForces 723A The New Year: Meeting Friends (水题)
- codeforces 680A A. Bear and Five Cards(水题)
- CodeForces 919B Perfect Number(水题)
- CodeForces 731B Coupons and Discounts (水题模拟)
- codeforces 22C System Administrator(构造水题)
- CodeForces--606A --Magic Spheres(模拟水题)
- CodeForces 339D Xenia and Bit Operations (线段树水题)
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
- 733B Parade codeforces(水题)
- codeforces 水题 37A-Towers
- CodeForces 589A Email Aliases STL水题
- codeforces水题100道 第二题 Codeforces Beta Round #4 (Div. 2 Only) A. Watermelon (math)
- codeforces水题100道 第二十四题 Codeforces Beta Round #85 (Div. 2 Only) A. Petya and Strings (strings)
- codeforces 133A HQ9+(字符串水题)
- CodeForces 939A(水题)
- Codeforces 632A Grandma Laura and Apples 【水题】