UVA7512 November 11th (思路)

来源:互联网 发布:计算量子电路矩阵 编辑:程序博客网 时间:2024/06/01 10:08

Description

It’s November 11-th, which is Singles’ Day! On this day, a certain
cinema is only allowing singles to watch movies there. Couples are
forbidden! There are R rows in this cinema, numbered 0, 1, · · ·, R−1.
In each row, there are S seats, numbered 0, 1, · · ·, S − 1. Singles
refuse to sit directly beside each other. Two seats are considered
beside each other if they are 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 the number 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 si is
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 is the 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

32 310 12 301 110 0

Sample Output

Case #1: 4 3Case #2: 4 2Case #3: 0 0

思路

有一个电影院,有n个座位是坏的,并且在坐人的时候,每两个人不能挨着坐,问要是这个电影院到达饱和状态,最大需要多少人,最小需要多少人?

记录一下坏了的座位的编号,然后计算每一行,推推公式就出来了,看代码吧

代码

#include <cstdio>#include <cstring>#include <string>#include <set>#include <cmath>#include <iostream>#include <stack>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define debug() puts("what the fuck!!!")#define ll long longusing namespace std;const int N=1010;int t,n,m,q=1,x,a,b;int main(){    scanf("%d",&t);    while(t--)    {        vector<int>num[N];        scanf("%d%d%d",&n,&m,&x);        while(x--)        {            scanf("%d%d",&a,&b);            num[a].push_back(b+1);        }        int maxx=0,minn=0;        for(int i=0; i<n; i++)        {            sort(num[i].begin(),num[i].end());            int bad=num[i].size();            if(bad==0)            {                if(m%3==0)                    minn+=m/3;                else                    minn+=m/3+1;                if(m&1)                    maxx+=(m+1)/2;                else                    maxx+=m/2;            }            else            {                num[i].insert(num[i].begin(),0);                num[i].insert(num[i].end(),m+1);                for(int j=1; j<num[i].size(); j++)                {                    int ans=num[i][j]-num[i][j-1]-1;                    if(ans&1)                        maxx+=(ans+1)/2;                    else                        maxx+=ans/2;                    if(ans-1>=0)                        minn+=(ans-1)/3+1;                }            }        }        printf("Case #%d: %d %d\n",q++,maxx,minn);    }    return 0;}