Codeforces Round #212 (Div. 2) A. Two Semiknights Meet /B. Petya and Staircases

A题:A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.

题解:这就是英文理解题了。。。在8*8的格子里面有两个K,他们只能向上走2次并且左或者右两次,或者向下走两次并且左或者右两次,'#'表示不可走。问这两个K都要走,能不能相遇,能则输出‘YES’。

我们只用考虑这两个k的坐标关系就可以了。假设两个K的x坐标x1,x2相差为2或者1,那么怎么走x坐标都没法相等。推导相差4或者4的倍数就可以了。

A题:

#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int T,x1,x2,y1,y2;
    char c;
    cin>>T;
        while(T--)
        {
            bool flag = false;
            for(int i=0;i<8;i++)
                for(int j=0;j<8;j++)
                {
                    cin>>c;
                    if(c=='K')
                    {
                        if(!flag)
                        {
                            x1=i;
                            y1=j;
                            flag= true;
                        }
                        else
                        {
                            x2=i,y2=j;
                        }
                    }
                }
            if(abs(x1-x2)%4==0&&abs(y1-y2)%4==0)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
}

B题:理解题意就可以做了。这个人跳台阶,第一个台阶和最后一个台阶都不能是脏的,并且连续3个台阶是脏的也GAME OVER。。

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[3003];
int n,m;
int main()
{
    while(cin>>n>>m)
    {
        bool ans= false ;
        for(int i=1;i<=m;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+1+m);
        if(a[1]==1||a[m]==n)
        {
            cout<<"NO"<<endl;
            continue;
        }
        int tmp=a[1];
        int cnt=0;
        for(int i=2;i<=m;i++)
        {

            if(a[i]-tmp==1)
            {
                cnt++;
                tmp=a[i];
            }
            else if(a[i]-tmp>1)
            {
                cnt=0;
                tmp=a[i];
            }
            if(cnt>=2)
            {
                ans=true;
                break;
            }
        }
        if(ans)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值