5.15 <407>总结

· · 个人记录

前言

555……掉了……掉到10多名去了

而且今天还是模拟😭😭😭

P2327

题意

有一个n \times 2的扫雷棋盘,给定第一列的雷,求第二列的雷的摆放数量。

思路

这题,一眼看上去,十分复杂,题目的颜色也告诉了你。

实则不然,连dfs都用不到,纯模拟。
我们只要按第一个雷怎么摆放的去模拟就行。由于作者词穷待会看代码。

错因

本来是想打dfs的,然后在考试的最后4分钟发现错了,改到一般就没时间了。

AC代码

#include <bits/stdc++.h>
using namespace std;

const int N = 1e4 + 5;
int n;
int ans;
int b[N];
bool tmp[N], a[N];
bool check()
{
    for(int i = 1; i <= n; i ++)//初始化
        a[i] = tmp[i];
    for(int i = 1; i < n; i ++)
    {
        int cnt = 0;//统计周围雷的个数
        if(a[i - 1] == 1)//前面是雷
            cnt ++;
        if(a[i] == 1)//对齐的是雷
            cnt ++;
        if(cnt == b[i])//雷的个数够了
            continue;
        if(cnt > b[i])//多了
            return 0;//肯定不行
        if(cnt == b[i] - 1)//说明下面还有雷
            a[i + 1] = 1;//给下一个标上
        else return 0;
    }
    //因第n个没有下一个,所以要单独判断
    int cnt = 0;//同上
    if(a[n - 1] == 1)
        cnt ++;
    if(a[n] == 1)
        cnt ++;
    if(cnt != b[n])//这里是“!=”哈,大于小于都算
        return 0;
    else return 1;
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> b[i];
    tmp[1] = 0;//第一个不放雷
    if(check() == 1)
        ans ++;
    tmp[1] = 1;//第一个放雷
    if(check() == 1)
        ans ++;
    cout << ans;
    return 0;
}

T761164

555 数据加强了😭😭😭

题意

有一个日期,形式为MM-DD,其中MM和DD都是两位数。问这个日期至少需要修改多少次才能是个合法日期。

思路

哭笑不得的我。 。 。

额……就是判断就行了。反正答案总共就两个,你不信可以试试。

别急,做个填空题:

十年OI一场空,不开____见祖宗

错因

我是按我原题的那个思路写的,可能本来就有些细节错误,导致WA。

AC代码

代码也是十分的好看

注释不需要了吧,真的就是试出来加点判断。

#include <bits/stdc++.h>
#define int long long//填空题答案
using namespace std;
int ans;
char a, b, c, d;
void work()
{
    cin >> a >> b >> c >> c >> d;
    int x = (a - '0') * 10 + (b - '0');
    int y = (c - '0') * 10 + (d - '0');
    if(y == 0 || y > 31)
    {
        if(x == 0 || x > 12) ans = 2;
        else ans = 1;
    }
    else if(y == 31)
    {
        if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12)
            ans = 0;
        else if(x == 2 || x == 4 || x == 6 || x == 9 || x == 11 || x == 0)
            ans = 1;
        else if(x >= 13 && x <= 19)
            ans = 1;
        else
        {
            int ge = x % 10;
            if(ge == 1 || ge == 2 || ge == 3 || ge == 5 || ge == 7 || ge == 8 || ge == 0)
                ans = 1;
            else ans = 2;
        }
    }
    else if(y == 30 || y == 29)
    {
        if(x == 2 || x == 0 || x > 12)
            ans = 1;
        else ans = 0;
    }
    else
    {
        if(x == 0 || x > 12)
            ans = 1;
        else ans = 0;
    }
    cout << ans << "\n";
}
signed main()
{
    int t;
    cin >> t;
    while(t --)
    {
        work();
    }
    return 0;
}

T761206

题意

给你一个长度为n的字符串s,每一次都可以进行以下其中一种操作:

问能够得到的不同的非空字符串的数量。

思路

首先,一眼看去,一个dfs。可惜是会T的。我才不会告诉你们这是凑字数的

那可以怎么优化呢?

一个字符串是不是一个后缀加一个字符组成?那这个问题就好办了,那是不是只要这个字符不一样就是一个新的字符串?所以我们只要统计字符串里面有多少个不同的字符就可以了。

错因

这么好的题,我当然是写dfs啦

AC代码

#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;
int n, m;
string s;
int cnt, ans;
int a[N], num[N];//num统计字符出现的数量
int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        memset(num, 0, sizeof num);
        cnt = ans = 0;
        cin >> n >> s;
        for(int i = 1; i <= n; i ++)
        {
            num[s[i - 1]] ++;
            if(num[s[i - 1]] == 1)//字符第一次出现
                cnt ++;
            ans += cnt;
        }
        cout << ans << "\n";
    }
    return 0;
}