The 19th Zhejiang Provincial Collegiate Programming Contest

The 19th Zhejiang Provincial Collegiate Programming Contest

今天跑去239和学姐vp 结果发现自己啥也不会QAQ

A. JB Loves Math

只能加上奇数或者减去偶数,且这个数字是固定的
分为三大类:

  1. \(a==b\),答案为0;
  2. \(a > b\),\(a-b\)为奇数,需要两步(先减去\(a-b+1\),再+1);为偶数则需要一步;
  3. \(a < b\),\(b-a\)为偶数,需要一步;为偶数时再分为两种情况讨论,具体见Code:
#include <bits/stdc++.h>

using namespace std;


int main () {
    int t;
    cin >> t;
    while (t --) {
        int a, b;
        cin >> a >> b;
        if (a > b) {
            if ((a - b) % 2 == 0)
                cout << 1 << endl;
            else
                cout << 2 << endl;
        }
        else if (a == b)
            cout << 0 << endl;
        else {
            if ((b - a) % 2)
                cout << 1 << endl;
            else if ((b - a) / 2 % 2)
                cout << 2 << endl;
            else
                cout << 3 << endl;
        }
    }
}
//改变奇偶性
//eg.2->6: +3 +3 -2
//答案不会超过3

B. JB Loves Comma

灰常灰常简单的签到题

#include <iostream>

using namespace std;

int main () {
    string s;
    cin >> s;
    int n = s.size ();
    if (n < 3)
        cout << s << endl;
    else {
        for (int i = 0; i < s.size (); i ++) {
            cout << s[i];
            if (s[i] == 'b' && s[i - 1] == 'j' && s[i - 2] == 'c')
                cout << ',';
        }
        cout << endl;
    }
    
}

C. JB Wants to Earn Big Money

题意已经很明确了,序列\({a_n}\)\(\geq x\)的就统计进ans; 序列\({b_n}\)\(\leq x\)的就统计进ans

#include <iostream>

using namespace std;
int ans;

int main () {
    int n, m, x;
    cin >> n >> m >> x;
    for (int i = 1; i <= n; i ++) {
        int t;
        cin >> t;
        if (t >= x)
            ans ++;
    }
    for (int i = 1; i <= m; i ++) {
        int t;
        cin >> t;
        if (t <= x)
            ans ++;
    }
    cout << ans << endl;
}

L. Candy Machine

其实我隐约有这个思路了,就是全部扫一遍。。但是我以为太暴力了就没说hhh下次还是要大胆一些!
思路:先排个序,然后按顺序挨个往里面加数,二分找出最大的该区间内严格大于该区间平均数的数的数量,记录一个最大值输出。
stl实现二分查找详细用法mark:
https://zh.cppreference.com/w/cpp/algorithm/upper_bound
https://zh.cppreference.com/w/cpp/algorithm/lower_bound

还有几道题目明天再补

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1e6 + 5;
int n, a[N], ans;

signed main () {
    scanf ("%d", &n);
    for (int i = 1; i <= n; i ++)
        scanf ("%d", &a[i]);

    sort (a + 1, a + n + 1);
    int sum = 0;
    for (int i = 1; i <= n; i ++) {
        sum += a[i];
        double aver = 1.0 * sum / i;
        int pos = upper_bound (a + 1, a + i + 1, aver) - a;
        ans = max (ans, i - pos + 1);
    }
    printf ("%d\n", ans);

}
//upper_bound是返回首个大于v的迭代器
//lower_bound是返回首个大于等于v的迭代器

//卧槽。。卡cin

M. BpbBppbpBB

本以为是一个很可怕的大模拟,没想到就是解方程orz
就是分别统计黑块和白块(注意不能统计到边上的了)的数目;第一种有黑块146个,白块24个;第二种有黑块100个,白块12个。
*这里统计白块就是看最左上角那个满不满足这样的图形:

 ####
 #..#
#....#
#....#
 #..#

看看check函数就明白了:
然后手动解方程,得

\[\begin{cases} 146x+100y=black\\ 24x+12y=white -> 2x+y=white'(大白块) \end{cases} \,\,\,\,\,\rightarrow \begin{cases} x = \frac{100white - black}{54}\\ y = \frac{black - 73white}{27} \end{cases}\\ \]

#include <bits/stdc++.h>

using namespace std;
const int N = 1005;
int n, m;
char a[N][N];

bool check (int x, int y) {
    if (a[x-1][y-1] == '#' && a[x-1][y] == '#' && a[x-1][y+1] == '#' && a[x-1][y+2] == '#' &&
        a[x][y-1] == '#' && a[x][y] == '.' && a[x][y+1] == '.' && a[x][y+2] == '#' &&
        a[x+1][y-2] == '#' && a[x+1][y-1] == '.' && a[x+1][y] == '.' && a[x+1][y+1] == '.' && a[x+1][y+2] == '.' && a[x+1][y+3] == '#' &&
        a[x+2][y-2] == '#' && a[x+2][y-1] == '.' && a[x+2][y] == '.' && a[x+2][y+1] == '.' && a[x+2][y+2] == '.' && a[x+2][y+3] == '#' &&
        a[x+3][y-1] == '#' && a[x+3][y] == '.' && a[x+3][y+1] == '.' && a[x+3][y+2] == '#' 
    )
        return true;
    return false; 
}

int main () {
    cin >> n >> m;
    int black = 0, white = 0;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++) {
            cin >> a[i][j];
            if (a[i][j] == '#')
                black ++;
        }

    //统计非边界白块
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++) {
            //按照左上角来看
            if (check (i, j))
                white ++;
        }
    

    cout << (100*white - black) / 54 << ' ' << (black - 73*white) / 27 << endl;

}
//统计白点和黑点的个数然后解方程
//注意边界也是白块啊

//146x+100y=black
//24x+12y=white -> 2x+y=white'(大白块)

//x = (100*white - black) / 54;
//y = (black - 73*white) / 27;

//笑死。。有人解方程都会解错
posted @ 2022-06-03 23:34  Sakana~  阅读(193)  评论(0编辑  收藏  举报