2024 ccpc 辽宁省赛 E(构造 思维?)L(二分+一点点数论知识?)

E 题意:
在这里插入图片描述
可以注意到:
我的两种方格都四个方格的大小。
所以 如果存在一种摆放方式 那么 4|nm。
再考虑一种特殊的情况 2
2 ,此时虽然我的积是4 但是无法摆放的。

1>对于 4 | n,或者 4 | m.我直接摆放第二种方格就可以了。
如果我n 是4 的倍数,那么竖着摆放。如果m 是4 的倍数,那么横着摆。

2>对于我n m 都不是4 的倍数的情况。(因为4|nm ,并且我n m 都不是4的倍数。所以n m 都是偶数,(因为每一个数都要贡献出一个2 出来)
我们可以构造出来的最小单元是 2
6
1 2 2 2 2 3
1 1 1 3 3 3

当m>2的时候。我两行两行的考虑
m至少为6
将原矩阵分成2m 个矩形
当m 大于2 并且不是4的倍数。那么m=4
k+6
对分割好的矩形 可以分割成k个24 的矩形和一个2 6的矩形。

当我的m==2 的时候
1 1
1 2
1 2
3 2
3 3
那么我n =4*k+6
和上文类似

我的构思代码

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

void fun1(int x)
{
    cout << x << " " << x + 1 << " " << x + 1 << " " << x + 1 << " " << x + 1 << " " << x + 2 << " ";
    return;
}
void fun2(int x)
{
    cout << x << " " << x << " " << x << " " << x + 2 << " " << x + 2 << " " << x + 2 << " ";
    return;
}
void fun3(int x)
{
    cout<<x<<" "<<x<<"\n";
    cout<<x<<" "<<x+1<<"\n";
    cout<<x<<" "<<x+1<<"\n";
    cout<<x+2<<" "<<x+1<<"\n";
    cout<<x+2<<" "<<x+1<<"\n";
    cout<<x+2<<" "<<x+2<<"\n";
    return ;
}
void solve()
{
    int n, m;
    cin >> n >> m;
    if (n == 2 && m == 2)
    {
        cout << "NO\n";
        return;
    }
    if ((n * m) % 4 != 0)
    {
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
    if (n % 4 == 0 || m % 4 == 0)
    {
        int tot = 0;
        if (m % 4 == 0)
        {
            for (int j = 1; j <= n; j++)
            {
                for (int k = 1; k <= m; k++)
                {
                    if (k % 4 == 1)
                        tot++;
                    cout << tot << " ";
                }
                cout << "\n";
            }
        }
        else
        {

            int tot = 1;
            for (int k = 1; k <= n / 4; k++)
            {
                for (int jj = 1; jj <= 4; jj++)
                {
                    for (int i = tot; i <= tot + m - 1; i++)
                    {
                        cout << i << " ";
                    }
                    cout << "\n";
                }
                tot += m;
            }
        }
        return;
    }
    int tot = 1;
    
    if (m==2)
    {
        int k=(n-6)/4;
        fun3(tot);
        tot+=3;
        for (int i=1;i<=k;i++)
        {
            for (int k=1;k<=4;k++)
            {
                cout<<tot<<" "<<tot+1<<"\n";
            }
            tot+=2;
           
        }

        return ;
    }
    int k = (m - 6) / 4;
    for (int i = 1; i <= n; i += 2)
    {
        int t = tot;
        // 两行 两行处理
        fun1(t);
        tot += 3;
        // 多少个四
        for (int j = 1; j <= k; j++)
        {

            for (int kk = 1; kk <= 4; kk++)
                cout << tot << " ";
            tot++;
        }
        cout << "\n";
        fun2(t);
        for (int j = 1; j <= k; j++)
        {
            for (int kk = 1; kk <= 4; kk++)
                cout << tot << " ";
            tot++;
        }
     
        cout << "\n";
    }
}
int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

L题意:
在这里插入图片描述

一直以为这是什么数论的题。
说到底还是不会枚举啊。读不懂题。真可恶 真可恶!!

1-x 中 是a 的倍数的数字有 x/a 个。(这里我其实是算的 我的x是a 的多少倍。若x/a=k。那么从1-x 中 存在着 a 2a …ka 一共k 个数)
(主要是对这 一句的理解)
n 是4*100^p 的倍数 但是我n 不是 100^{p+1} 的倍数
如果我确定了p.那么我可以用 mid/a-mid/b;
同时要减去1-2024 年的影响。

我的平年 和我的年份 具有单调性。(不降的)
所以我二分年份
因为我的平年至多是1e18 。所以我的p 取到 8 就可以了。4100^p 已经到达了41e16
当我的p 取9 的时候,是 4*1e18,那必然不会出现倍数了

void solve()
{
    int k;
    cin >> k;
    auto check = [&](int mid) -> bool
    {
        int ans = 0;
        for (int i = 0; i <= 8; i++)
        {
            ans += mid / (4 * qpow(100, i)) - mid / (qpow(100, i + 1));
        }
 
        return (mid - 2024 - (ans - 491)) >= k;
    };
 
    int l = 2025;
    int r = 2e18;
    while (l <= r)
    {
        int mid = l + r >> 1;
        if (check(mid))
            r = mid - 1;
        else
            l = mid + 1;
    }
    cout << r + 1 << "\n";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值