2021上海站补题

文章目录

B题

  • 题意
    玩扫雷的应该很快就会看懂,我看了半个小时才看懂。
    就是分为雷区和非雷区。非雷区格子上面有一个数字,代表它的八个方向的雷区的数量。
    给你 A 、 B A、B AB,两个地图,要你在 B B B 的基础上更改不超过 ⌊ n m 2 ⌋ \lfloor \frac{nm}{2} \rfloor 2nm 个点,使得 A 、 B A、B AB 两个地图上的非雷区上的数字之和相等。
  • 思路

反转一个地图中的雷区和非雷区,得到的非雷区中的数字之和是一样的。
简单证明一下

最后的答案可以这么算
每一个雷对于八个方向都贡献了 1 1 1 ,而每一个非雷区的数字来自八个方向的雷,这样是相等的;那反过来也必然相等(狗头)。

所以有了这个性质就很好构造了,直接把 B B B 变成 A A A,或者 A A A 的取反。

  • 代码
#include <bits/stdc++.h>

using namespace std;
const int N = 1e3 +10;

char A[N][N],B[N][N];
int main()
{
    int n,m;cin>>n>>m;
    for(int i = 1;i <= n;i ++){
        for(int j = 1;j <= m;j ++) cin>>A[i][j];
    }
    int ans = 0;
    for(int i = 1;i <= n;i ++){
        for(int j = 1;j <= m;j ++) 
        {
            cin>>B[i][j];
            if(A[i][j] != B[i][j]){
                ans ++;
            }
        } 
    }
    if(ans > n*m/2){
        for(int i = 1;i <= n;i ++){
            for(int j = 1;j <= m;j ++){
                if(A[i][j] == '.')cout<<'X';
                else cout<<".";
            }
            puts("");
        }
    }
    else{
        for(int i = 1;i <= n;i ++){
            for(int j = 1;j <= m;j ++) cout<<A[i][j];
            puts("");
        }
    }
}

希望能一直绿下去
在这里插入图片描述

G题

  • 题意
    在这里插入图片描述
  • 思路
    其实化简下来就是求前 n n n F i b o n a c c i Fibonacci Fibonacci 项可以有多少组乘积为偶数。
    F i b o n a c c i Fibonacci Fibonacci 是有规律的-奇奇偶,所以答案就是 ( n − t ) ∗ t + t ∗ ( t − 1 ) / 2 (n-t)*t+t*(t-1)/2 (nt)t+t(t1)/2
  • 代码
#include<iostream>

using namespace std;

int main()
{
    int n;cin>>n;
    long long ans = n/3;
    long long res = (n-ans)*ans + ans*(ans-1)/2;
    cout<<res<<endl;
}

M题

  • 题意
    在这里插入图片描述
    英语不行啊,当时就卡在了最后两句话上,翻译为“然后是 n n n 行”,就可以理解为给出的 n + m n+m n+m 行,前 n n n 行是需要 i g n o r e d ignored ignored 的。
  • 思路
    直接模拟——如果这个文件夹下出现了不能 i g n o r e d ignored ignored 的,那就往下走;否则就直接 i g n o r e d ignored ignored 这个文件夹,直接放到 set 里,就不用判重了,或者再用一个 H a s h Hash Hash 表。
  • 代码
#include <bits/stdc++.h>

using namespace std;
const int N = 110;
string a[N];
void solve()
{
    int n,m;cin>>n>>m;
    
    for(int i = 1;i <= n;i ++){
        cin>>a[i];
    }
    unordered_map<string,int> Hsh;
    for(int i = 1;i <= m;i ++){
        string s;cin>>s;
        string ts = "";
        for(int j = 0;j <s.size();j ++){
            if(s[j] == '/'){
                Hsh[ts] = 1;
            }
            ts += s[j];
        }
        Hsh[ts] = 1;
    }
    set<string> ans;
    for(int i = 1; i<= n;i ++){
        string s = a[i];
        string ts = "";
        for(int j = 0;j < s.size();j ++){
            if(s[j] == '/'){
                if(!Hsh[ts]){
                    ans.insert(ts);
                    break;
                }
            }
            ts += s[j];
        }
        if(!Hsh[ts]) ans.insert(ts); 
    }
    cout<<ans.size()<<endl;
}

int main()
{
    int t;cin>>t;
    while(t--){
        solve();
    }
}

D题

  • 题意
    在一条数轴上,有两个人,位置,速度分别是 p 1 , p 2 , v 1 , v 2 p_1,p_2,v_1,v_2 p1,p2,v1,v2
    在任意时刻都可以换方向,问这条数轴被覆盖(至少一个人走过)的最少时间为 ? ?

  • 思路

  • 代码


有些不会,看大佬的吧
第二篇

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯狂的码泰君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值