Codeforces Round #288 (Div. 2)

A - Pasha and Pixels


Description

Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.

Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with mpixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.

Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.

Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.

Input

The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 10001 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.

The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.

Output

If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.

If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.

Sample Input

Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0

给跪了,A题在row和lie都等于1的时候一个手残我看了20多分钟。。。。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[2000][2000];
int main()
{
    int n,m,k,row,lie;

    while(~scanf("%d %d %d",&n,&m,&k))
    {
        memset(a,0,sizeof(a));
        int e=0;
        for(int  i=1; i<=k; i++)
        {
            scanf("%d %d",&row,&lie);
            a[row][lie]=1;
            if(e)
                continue;
            if(row==1&&lie==1)
            {
                if(a[1][1]==1&&a[1][2]==1&&a[2][1]==1&&a[2][2]==1)
                {
                    if(e==0)
                        e=i;
                }
            }
            else if(row==1&&lie>1)
            {
                if(a[1][lie]==1&&a[2][lie]==1&&a[1][lie+1]==1&&a[2][lie+1]==1)
                {
                    if(e==0)
                        e=i;
                }
                else if(a[1][lie]==1&&a[2][lie]==1&&a[1][lie-1]==1&&a[2][lie-1]==1)
                {
                    if(e==0)
                        e=i;
                }
            }
            else if(lie==1&&row>1)
            {
                if(a[row][1]==1&&a[row][2]==1&&a[row+1][1]==1&&a[row+1][2]==1)
                {
                    if(e==0)
                        e=i;
                }
                else if(a[row][1]==1&a[row][2]==1&&a[row-1][1]==1&&a[row-1][2]==1)
                {
                    if(e==0)
                        e=i;
                }
            }
            else
            {
                if(a[row][lie]==1&&a[row][lie+1]==1&&a[row+1][lie]==1&&a[row+1][lie+1]==1)
                {
                    if(e==0)
                        e=i;
                }
                else if(a[row][lie]==1&&a[row+1][lie]==1&&a[row][lie-1]==1&&a[row+1][lie-1]==1)
                {
                    if(e==0)
                        e=i;
                }
                else if(a[row][lie]==1&&a[row-1][lie]==1&&a[row][lie-1]==1&&a[row-1][lie-1]==1)
                {
                    if(e==0)
                        e=i;
                }
                else if(a[row][lie]==1&&a[row-1][lie]==1&&a[row][lie+1]==1&&a[row-1][lie+1]==1)
                {
                    if(e==0)
                        e=i;
                }
            }
        }
        printf("%d\n",e);
    }
    return 0;
}
<span style="font-size: 24px;  text-align: center; color: green;"><strong>B - </strong></span><span style="color: rgb(0, 0, 255); font-size: 24px;  text-align: center;"><strong>Anton and currency you all know</strong></span>

Description

Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.

Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!

Input

The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.

Output

If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1.

Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.

Sample Input

Input
527
Output
572
Input
4573
Output
3574
Input
1357997531
Output
-1

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char a[200000],str[200000];
int main()
{

    while(~scanf("%s",a))
    {
        strcpy(str,a);
        int len=strlen(a);
        int maxid1=-1,maxid2=-1;
        for(int i=0; i<len-1; i++)
        {
            int b=a[i]-'0';
            int d=a[len-1]-'0';
            if(b%2==0)
            {
                if(d>b)
                {
                    maxid1=i;
                    break;
                }
                else
                {
                       maxid2=i;
                }
            }
        }
        //printf("%d %d\n",maxid1,maxid2);
        if(maxid1!=-1)
        {
            char t=a[maxid1];
            a[maxid1]=a[len-1];
            a[len-1]=t;
        }
        else if(maxid1==-1&&maxid2!=-1)
        {
            char t=a[maxid2];
            a[maxid2]=a[len-1];
            a[len-1]=t;
        }
        else
        {
            printf("-1\n");
            continue;
        }
        /*int c=strcmp(a,str);
        if(c==1)
            puts(a);
        else
            printf("-1\n");*/
            puts(a);
    }
    return 0;
}
c题一道简单的贪心,只要注意一下到底是什么时候算是蜡烛燃烧,开始的时候鬼来的时间可以小于k,因为你可以0点以前就点燃蜡烛

C - Anya and Ghosts

Description

Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.

For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.

What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

Input

The first line contains three integers mtr (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.

The next line contains m space-separated numbers wi (1 ≤ i ≤ m1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.

Output

If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.

If that is impossible, print  - 1.

Sample Input

Input
1 8 3
10
Output
3
Input
2 10 1
5 8
Output
1
Input
1 1 3
10
Output
-1

Hint


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int m,t,k;
    int s=0;
    int a[2000],b[2000];
    while(~scanf("%d %d %d",&m,&t,&k))
    {
        for(int i=0; i<m; i++)
            scanf("%d",&a[i]);
        sort(a,a+m);
        if(t<k)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            s=k;
            for(int i=0; i<k; i++)
                b[i]=t-i;
            for(int i=1; i<m; i++)
            {
                int ti=a[i]-a[i-1];
                int l=0;
                for(int j=0; j<k; j++)
                {
                    if(b[j]-ti<=0)
                    {
                        b[j]=t-l;
                        l++;
                        s++;
                    }
                    else
                        b[j]=b[j]-ti;
                }
            }
        }
        printf("%d\n",s);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值