7月1日【水题日记】

暑假补补题

A. Tenzing and Tsondu

比较一下值的大小就行

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
const int N = 3e5 + 10;

void solve()
{
    int n, m;
    cin >> n >> m;
    long long ans1 = 0;
    for (int i = 1; i <= n; i++)
    {
        long long x;
        cin >> x;
        ans1 += x;
    }
    for (int i = 1; i <= m; i++)
    {
        long long x;
        cin >> x;
        ans1 -= x;
    }
    if (ans1 > 0)
        cout << "Tsondu\n";
    else if (ans1 == 0)
        cout << "Draw\n";
    else
        cout << "Tenzing\n";
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

B. Tenzing and Books

给定3n个数,问能不能按位或成x

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
const int N = 3e5 + 10;
long long a[N], b[N], c[N];

void to_bit(int x, string &s)
{
    s.clear();
    if (x == 0)
    {
        s = '0';
        return;
    }
    while (x)
    {
        if (x % 2)
            s += '1';
        else
            s += '0';
        x = x / 2;
    }

    // cout << s << endl;
}
void solve()
{
    long long n, x;
    string bit_s;
    cin >> n >> x;
    to_bit(x, bit_s);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    for (int i = 1; i <= n; i++)
        cin >> c[i];
    int a1 = 1, b1 = 1, c1 = 1;
    long long ans = 0;
    while (true)
    {
        if (ans == x)
        {
            cout << "YES\n";
            return;
        }
        string s;
        if ((long long)(ans | a[a1]) <= x && a1 <= n)
        {
            to_bit(a[a1], s);
            int flag = 0;
            if (s.size() > bit_s.size())
                flag = 1;
            for (int i = 0; i < bit_s.size(); i++)
            {
                if (i < s.size())
                    if (bit_s[i] == '0' && s[i] == '1')
                    {
                        flag = 1;
                        break;
                    }
            }
            if (flag == 0)
            {
                ans = (ans | a[a1++]);
                continue;
            }
        }
        if ((long long)(ans | b[b1]) <= x && b1 <= n)
        {
            to_bit(b[b1], s);
            int flag = 0;
            if (s.size() > bit_s.size())
                flag = 1;
            for (int i = 0; i < bit_s.size(); i++)
            {
                if (i < s.size())
                    if (bit_s[i] == '0' && s[i] == '1')
                    {
                        flag = 1;
                        break;
                    }
            }
            if (flag == 0)
            {
                ans = (ans | b[b1++]);
                continue;
            }
        }
        if ((long long)(ans | c[c1]) <= x && c1 <= n)
        {
            to_bit(c[c1], s);
            int flag = 0;
            if (s.size() > bit_s.size())
                flag = 1;
            for (int i = 0; i < bit_s.size(); i++)
            {
                if (i < s.size())
                {
                    if (bit_s[i] == '0' && s[i] == '1')
                    {
                        flag = 1;
                        break;
                    }
                }
                else
                    break;
            }
            if (flag == 0)
            {
                ans = (ans | c[c1++]);
                continue;
            }
        }
        if (ans != x)
        {
            cout << "NO\n";
            return;
        }
    }
    if (ans != x)
    {
        cout << "NO\n";
        return;
    }
    else
    {
        cout << "YES\n";
        return;
    }
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

重复的有点多,其实就是判断一下对应二进制的值就行,按位或会越来越大,当x的那一位是0的时候,判断的那个数对应位必须是0,其他的随便,不过好像判断一下&就可以通过

A. Forbidden Integer

给定n,k,x,问能不能从1-k中选出数组成n,不能用x

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
const int N = 3e5 + 10;

void solve()
{
    int n, x, k;
    cin >> n >> k >> x;

    for (int i = 1; i <= k; i++)
    {
        if (i == x)
            continue;
        if (n % i != x)
        {
            int ans = 0;
            ans = n / i;
            if (n % i)
                ans += 1;
            cout << "YES\n";
            cout << ans << endl;
            while (ans--)
                cout << i << " ";
            if (n % i)
                cout << n % i;
            cout << endl;
            return;
        }
        else if (n % i + i <= k)
        {
            cout << "YES\n";
            int ans = 0;
            ans = n / i - 2;
            if (n % i)
                ans += 1;
            cout << ans + 1 << endl;
            while (ans--)
                cout << i << " ";
            if (n % i)
                cout << n % i + i;
            cout << endl;
            return;
        }
    }
    cout << "NO\n";
    return;
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

直接判断都行,一直模除看剩下的那个数是不是x如果是的话就给一个i再看一下能不能小于k

B. Come Together

两个人一起回家,问最大公共路径

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
const int N = 3e5 + 10;

void solve()
{
    int a1, a2, b1, b2, c1, c2;
    if ((a1 == b1 && a2 == b2) || (a1 == c1 && a2 == c2))
    {
        cout << 0 << endl;
        return;
    }
    long long ans = 1;
    cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;
    if (c1 - a1 > 0 && b1 - a1 > 0)
    {
        ans += abs(min(b1, c1) - a1);
    }
    else if (c1 - a1 < 0 && b1 - a1 < 0)
    {
        ans += abs(max(b1, c1) - a1);
    }
    if (c2 - a2 > 0 && b2 - a2 > 0)
    {
        ans += abs(min(b2, c2) - a2);
    }
    else if (c2 - a2 < 0 && b2 - a2 < 0)
    {
        ans += abs(max(b2, c2) - a2);
    }
    cout << ans << endl;
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

看一下他两是不是同一个方向上的,如果是同一个方向上的话就可以减去离a最近的那个点的值,然后把x和y的值加起来就行,要看一下是在a的上面(左)还是a得下面(右)

C. Strong Password

给一组数字,一个长度,两个区间范围,从这两个区间的每一位中选数,最终使得选出来的数不是给定数字的子序列(不连续)

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <vector>
using namespace std;
const int N = 3e5 + 10;

void solve()
{
    string s, l, r;
    int m;
    cin >> s >> m >> l >> r;
    int ans = 0, cnt = 0;
    for (int i = 0; i < m; i++)
    {
        int nxt = ans;
        for (char j = l[i]; j <= r[i]; j++)
        {
            int p = nxt;
            while (p < s.size() && s[p] != j)
                p += 1;
            if (p >= s.size())
            {
                cout << "YES\n";
                return;
            }
            ans = max(ans, p + 1);
        }
    }
    cout << "NO\n";
    return;
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

整体不是原数字的子序列,每一个值的位置尽可能的靠右是最好的,然后就往右找就行,如果超出了范围那么剩下的数怎么放都行(都不是原数字的子序列了)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值