UVALive 7512 November 11th

题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5534

It’s November 11-th, which is Singles’ Day! On this day, a certain cinema is only allowing singles towatch movies there. Couples are forbidden!

There are R rows in this cinema, numbered 0, 1, · · ·, R−1. In each row, there are S seats, numbered0, 1, · · ·, S − 1.

Singles refuse to sit directly beside each other. Two seats are considered beside each other if theyare in the same row and they have consecutive seat numbers.

There are a total of B broken seats in the cinema, and nobody can sit in a broken seat.

The cinema owner has asked you to find two values:

• The maximum possible number of singles that could sit in this cinema

• The minimum number of singles needed to occupy the cinema so that no more singles can sit

Input

The first line of the input gives the number of test cases, T. T test cases follow.

Each test case starts with one empty line and then 2 integers R and S, the number of rows and thenumber of seats per row.

The next line consists of a number B. Then B lines follow; each has two 2 integers ri and si,indicating that in row ri, seat siis broken. All of the broken seats will be different.

Output

For each test case, output one line containing ‘Case #x: y z’, where x is the test case number(starting from 1), y is the maximum possible number of singles that could sit in this cinema, and z isthe minimum possible number of singles that could occupy the cinema.

Limits:

• 1 ≤ T ≤ 100.

• 1 ≤ R, S ≤ 1000.

• 0 ≤ B ≤ 1000.

• 0 ≤ ri ≤ R − 1.

• 0 ≤ si ≤ S − 1.

Note: In Case #1, up to four singles can fit in the cinema:

SBS

S.S

However, it is possible for three singles to occupy the cinema:

SBS

.S.

Sample Input

3

2 3

1

0 1

2 3

0

1 1

1

0 0

Sample Output

Case #1: 4 3

Case #2: 4 2

Case #3: 0 0

提示

题意:

11月11日是单身狗的节日,一家电影院专门为他们开放,影院有r(1<=r<=1000)行座位,每行有s(1<=s<=1000)个座位,他们是不会坐在同一行旁边有人的情况。并且影院有b(0<=b<=1000)个座位是坏的,无法坐人,请求出影院最大能容下几个人和最少能容下几个人。

思路:

不仅S.S合法,S..S也是合法的,即两人最大间隙为2,最小间隙为1,因为这点一直过不了。

每行是独立的,我们针对于单行来看,每遇到坏的座位或边界就进行计算一次,求最大时(num+1)/2便是能坐的人数,求最小时(num+2)/3便是能坐的人数。

示例程序

#include <cstdio>
#include <cstring>
using namespace std;
int map[1000][1000];
int main()
{
    int t,i,i1,i2,r,c,n,x,y,num,ans,ans1;
    scanf("%d",&t);
    for(i=1;t>=i;i++)
    {
        scanf("%d %d",&r,&c);
        memset(map,0,sizeof(map));
        ans=0;
        ans1=0;
        scanf("%d",&n);
        for(i1=1;n>=i1;i1++)
        {
            scanf("%d %d",&x,&y);
            map[x][y]=1;				//坏座位处理
        }
        for(i1=0;r>i1;i1++)
        {
            num=0;
            for(i2=0;c>i2;i2++)
            {
                if(map[i1][i2]==1)			//遇到坏座位计算一次
                {
                    ans=ans+(num+1)/2;
                    ans1=ans1+(num+2)/3;
                    num=0;
                }
                else
                {
                    num++;
                }
            }
            ans=ans+(num+1)/2;				//边界再计算一次
            ans1=ans1+(num+2)/3;
        }
        printf("Case #%d: %d %d\n",i,ans,ans1);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值