Codeforces Round 864 (Div. 2) (A~C)

A. Li Hua and Maze

分析

如果有点在矩形的四个角,那么用两个方块就堵住了,如果点在矩形的四条边上不在四个角上,用三个方块也就行了,其他情况用4个方块将一个点的上下左右都堵住即可。

代码

#include<bits/stdc++.h>

using namespace std;

const int N = 100010,mod = 1e6+7;
typedef long long ll;
typedef pair<int,int> pii;

int n,m,k;

void solve()
{
    cin >> n >> m;
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int ans;
    if(((x1 == 1 || x1 == n) && (y1 == 1 || y1 == m)) || ((x2 == 1 || x2 == n) && (y2 == 1 || y2 == m)))
    {
        ans = 2;
    }
    else if(x1 == 1 || x1 == n || y1 == 1 || y1 == m || x2 == 1 || x2 == n || y2 == 1 || y2 == m)
    {
        ans = 3;
    }
    else 
    {
        ans = 4;
    }
    cout << ans << '\n';
}

int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    int T;
    T = 1;
    cin >> T;
    while(T--) solve();
    return 0;
}

B. Li Hua and Pattern

昨晚做傻了,思路没错,但过不了,才发现n为奇数有的点没遍历到。

分析

k次操作后,该图形关于中心对称,分情况讨论,当边长为奇数时,只用将关于中心对成的点变的相等即可,而边长为偶数时,除了关于中心对称还有剩余的操作次数是偶数。

代码

#include<bits/stdc++.h>

using namespace std;

const int N = 100010,mod = 1e6+7;
typedef long long ll;
typedef pair<int,int> pii;

int n,m,k;
int g[10000100];

void solve()
{
    cin >> n >> k;
    for(int i = 1;i <= n * n; i++) cin >> g[i];
    
    if(n % 2)
    {
        for(int i = 1;i <= n * n / 2; i++) 
            if(g[i] != g[n*n-i+1]) k--;
        if(k < 0) cout << "NO" << '\n';
        else cout << "YES" << '\n';
    }
    else 
    {
        for(int i = 1;i <= n * n / 2; i++)
            if(g[i] != g[n*n-i+1]) k--;
        if(k < 0 || k % 2) cout << "NO" << '\n';
        else cout << "YES" << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    T = 1;
    cin >> T;
    while(T--) solve();
    return 0;
}

C. Li Hua and Chess

交互题做的比较少,不过好像这也就是个思维题,不怎么会,自己看题解去了。

分析

假设(1,1)与king的距离为k,其实我们,可以的到(1,k+1)->(k+1,k+1),(k+1,1)-(k+1,k+1)都是符合距离的点,比较巧妙的点是对(k+1,1)和(1,k+1)进行访问,分别与king的距离假设为p和q,如果p=q的话,从下图可以知道king在(k+1,k+1)。如果p<q,king的位置在(k+1,p+1),如果p>q,king的位置在(q+1,k+1)。注意的点是,有可能得到的k可能大于n,m,所有进行处理或分类讨论都行。

 代码

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int N = 100010,mod = 1e9+7;
int n,m;

void solve()
{
    cin >> n >> m;
    cout << "? 1 1\n";
    cout.flush();
    int k;
    cin >> k;
    int p, q;
    cout << "? " << min(k+1,n) << " 1\n";
    cout.flush();
    cin >> p;
    cout << "? 1 " << min(k+1,m) << '\n';
    cout.flush();
    cin >> q;
    if(p == q) cout << "! " << k+1 << ' ' << k+1 << '\n';
    else if(p > q) cout << "! " << q+1 << ' ' << k+1 << '\n';
    else cout << "! " << k+1 << ' ' << p+1 << '\n';
    cout.flush();
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值