第九届蓝桥杯C++B组省赛

第几天

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    cout << 31 + 29 + 31 + 30 + 4 << endl;
    return 0;
}

明码

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int num, k = 0;
    while (cin >> num)
    {
        for (int i = 7; i >= 0; i -- )
            if (num >> i & 1)
                cout << "*";
            else
                cout << ' ';
        k ++ ;
        if (k == 2)
        {
            k = 0;
            puts("");
        }
    }
    return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long LL;

int main()
{
    LL res = pow(9, 9);
    cout << res << endl;
    return 0;
}

测试次数

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>

using namespace std;

const int N = 10010;

int n;
int f[4][N];

int main() {
    //scanf("%d", &n);
    n = 1000;
    memset(f, 0x3f3f3f, sizeof f);
    
    for (int i = 0; i <= n; i ++ )
        f[1][i] = i;
        
    for (int i = 2; i <= 3; i ++ )
    {   
        f[i][0] = 0;
        for (int j = 1; j <= n; j ++ )
            for (int k = 1; k <= j; k ++ )
            {
                f[i][j] = min(f[i][j], max(f[i - 1][k - 1], f[i][j - k]) + 1);
            }
    }
    
    printf("%d\n", f[3][n]);
    return 0;
}

快速排序

#include <stdio.h>

int quick_select(int a[], int l, int r, int k) {
    int p = rand() % (r - l + 1) + l;
    int x = a[p];
    {int t = a[p]; a[p] = a[r]; a[r] = t;}
    int i = l, j = r;
    while(i < j) {
        while(i < j && a[i] < x) i++;
        if(i < j) {
            a[j] = a[i];
            j--;
        }
        while(i < j && a[j] > x) j--;
        if(i < j) {
            a[i] = a[j];
            i++;
        }
    }
    a[i] = x;
    p = i;
    if(i - l + 1 == k) return a[i];
    if(i - l + 1 < k) return quick_select(a, i, r, k - (i - l + 1)); //填空
    else return quick_select(a, l, i - 1, k);
}
    
int main()
{
    int a[100];
    int n;
    scanf("%d %d",&n);
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    printf("%d\n", quick_select(a, 0, n-1, 5));
    return 0;
}

递增三元组

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 100010;

int n;
LL res = 0;
int a[N], b[N], c[N];

int main()
{
    int l = 0, r = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
    for (int i = 0; i < n; i ++ ) scanf("%d", &b[i]);
    for (int i = 0; i < n; i ++ ) scanf("%d", &c[i]);
    
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    
    for (int i = 0; i < n; i ++ )
    {
        while (l < n && a[l] < b[i]) l ++ ;
        while (r < n && c[r] <= b[i]) r ++ ;
        
        res += (LL)l * (n - r);
    }
    printf("%lld\n", res);
    return 0;
}

螺旋折线

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

int main()
{
    int x, y;
    cin >> x >> y;
    
    int n;
    if (abs(x) <= y)
    {
        n = y;
        cout << (LL)(2 * n - 1) * 2 * n + x - (-n) << endl;
    }
    else if (abs(y) <= x)
    {
        n = x;
        cout << (LL)(2 * n) * (2 * n) + n - y << endl;
    }
    else if (abs(x) <= abs(y) + 1 && y < 0)
    {
        n = abs(y);
        cout << (LL)(2 * n) * (2 * n + 1) + n - x << endl;
    }
    else
    {
        n = abs(x);
        cout << (LL)(2 * n - 1) * (2 * n - 1) + y - (-n + 1) << endl;
    }
    return 0;
}

日志统计

#include <iostream>
#include <cstring>
#include <algorithm>

#define x first
#define y second

using namespace std;
const int N = 100010;
typedef pair<int, int> PII;

PII logs[N];
int cnt[N];
bool st[N];

int n, d, k;

int main()
{
    scanf("%d%d%d", &n, &d, &k);
    
    for (int i = 0; i < n; i ++ )
    {
        scanf("%d%d", &logs[i].x, &logs[i].y);
    }
    
    sort(logs, logs + n);
    
    for (int i = 0, j = 0; i < n; i ++ )
    {
        int id = logs[i].y;
        cnt[id] ++ ;
        
        while (logs[i].x - logs[j].x >= d)
        {
            cnt[logs[j].y] -- ;
            j ++ ;
        }
        
        if (cnt[id] >= k) st[id] = true;
    }
    
    for (int i = 0; i < N; i ++ )
        if (st[i])
            printf("%d\n", i);
    return 0;
}

全球变暖

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1010;

char g[N][N];
int cnt, sum, n;
bool st[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

void dfs(int x, int y)
{
    st[x][y] = true;
    
    sum ++ ;
    bool flag = false;
    for (int i = 0; i < 4; i ++ )
    {
        int sx = x + dx[i], sy = y + dy[i];
        if (sx < 0 || sx >= n || sy < 0 || sy >= n) continue;
        if (g[sx][sy] == '.') 
        {
            flag = true;
            continue;
        }
        if (st[sx][sy]) continue;
        
        dfs(sx, sy);
    }
    
    if (flag) cnt ++ ;
}

int main()
{
    scanf("%d", &n);
    
    for (int i = 0; i < n; i ++ ) scanf("%s", g[i]);
    
    int res = 0;
    for (int i = 0; i < n; i ++ )
        for (int j = 0; j < n; j ++ )
            if (g[i][j] == '#' && !st[i][j])
            {
                sum = 0, cnt = 0;
                dfs(i, j);
                if (sum == cnt) res ++ ;
            }
    cout << res << endl;
    return 0;
}

乘积最大

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 100010;
const int mod = 1000000009;
int n, k;
LL a[N];

int main()
{
    scanf("%d%d", &n, &k);
    
    for (int i = 0; i < n; i ++ ) scanf("%lld", &a[i]);
    
    sort(a, a + n);
    
    LL res = 1;
    int l = 0, r = n - 1;
    int sign = 1;
    if (k & 1)
    {
        res *= a[r];
        k -- ;
        r -- ;
        if (res < 0) sign = -1;
    }
    
    while (k)
    {
        LL x = a[l] * a[l + 1], y = a[r] * a[r - 1];
        if (x * sign > y * sign)
        {
            res = x % mod * res % mod;
            l += 2;
        }
        else
        {
            res = y % mod * res % mod;
            r -= 2;
        }
        k -= 2;
    }
    printf("%lld\n", res);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Shirandexiaowo

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

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

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

打赏作者

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

抵扣说明:

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

余额充值