上海月赛-8月丙组参考代码

题目

https://iai.sh.cn/contest/index

T1

#include <iostream>
using namespace std;

int main()
{
    int n, cnt = 0;

    while(cin >> n)
    {
        cnt++;
    }

    if(3 == cnt)
    {
        if(6 == n)
        {
            cout << 1000;
        }
        else
        {
            cout << 100;
        }
    }
    else if(2 == cnt)
    {
        cout << 10;
    }
    else
    {
        cout << 0;
    }

    return 0;
}

T2

#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int cnt = a;
    int b1 = a;
    int c1 = a;
    while(b1 >= b || c1 >= c)
    {
        if(b1 >= b)
        {
            cnt += b1 / b;
            c1 += b1 / b;
            b1 = b1 % b + b1 / b;
        }

        if(c1 >= c)
        {
            cnt += c1 / c;
            b1 += c1 / c;
            c1 = c1 % c + c1 / c;
        }
    }

    cout << cnt;

    return 0;
}

T3

#include <iostream>
#include <algorithm>
using namespace std;

const int maxN = 1e6 + 5;

struct antique
{
    string name;
    bool flag;  //1为真品,0为赝品
    int year;
    int hard;
    int value;
}ant[maxN];

int main()
{
    freopen("T3.txt", "r", stdin);

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> ant[i].name >> ant[i].year >> ant[i].hard >> ant[i].value;
        ant[i].flag = true;
    }

    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            if(ant[i].year - ant[j].year >= 100 || ant[i].hard - ant[j].hard >= 100 || ant[i].value - ant[j].value >= 100)
            {
                ant[j].flag = false;
            }

            if(ant[j].year - ant[i].year >= 100 || ant[j].hard - ant[i].hard >= 100 || ant[j].value - ant[i].value >= 100)
            {
                ant[i].flag = false;
            }
        }
    }

    bool noAntique = true;
    for(int i = 1; i <= n; i++)
    {
        if(ant[i].flag)
        {
            if(noAntique)
            {
                noAntique = false;
                cout << "Winning list:" << endl;
            }
            cout << ant[i].name << endl;
        }
    }

    if(noAntique)
    {
        cout << "There is no winner." << endl;
    }

    return 0;
}

T4

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

const int maxN = 2e5 + 5;
int cnt[maxN];

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        int num;
        cin >> num;
        cnt[num]++;
    }

    sort(cnt, cnt + maxN, greater<int>());

    long long sum = 0;
    for(int i = k; i < maxN; i++)
    {
        if(0 == cnt[i])
        {
            break;
        }
        sum += cnt[i];
    }

    cout << sum;

    return 0;
}

T5

#include <iostream>
using namespace std;

const int maxN = 2048 + 5;
char a[maxN][maxN];
int rows, cols; //最外边三角形共有多少行多少列

struct point
{
    int row;
    int col;
};

//根据三个顶点,填充三角形的边
void fillSides(point top, point L, point R)
{
    if(4 == R.col + 1 - L.col)
    {
        for(int r = top.row; r <= L.row; r++)
        {
            for(int c = L.col; c <= R.col; c++)
            {
                if(/*c <= top.col && */r + c == top.row + top.col)
                {
                    a[r][c] = '/';
                }

                if(/*c > top.col && */r - top.row == c - top.col - 1)
                {
                    a[r][c] = '\\';
                }
            }
        }

        for(int c = L.col + 1; c < R.col; c++)
        {
            a[L.row][c] = '_';
        }

        return;
    }

    //求三个顶点
    point L1{top.row + (L.row + 1 - top.row) / 2 - 1, L.col + (top.col + 1 - L.col) / 2};
    point L2{L1.row, top.col + (R.col + 1 - top.col) / 2};
    point mid{L.row, L.col + (R.col + 1 - L.col) / 2 - 1};

    //递归填充3个三角形的边
    fillSides(top, L1, L2);
    fillSides({L1.row + 1, L1.col - 1}, L, mid);
    fillSides({L2.row + 1, L2.col}, {mid.row, mid.col + 1}, R);
}

int main()
{
    int n;
    cin >> n;
    int pow2[11] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
    rows = pow2[n];
    cols = pow2[n + 1];

    for(int i = 1; i <= rows; i++)
    {
        for(int j = 1; j <= cols; j++)
        {
            a[i][j] = ' ';
        }
    }

    point top{1, cols / 2}, L{rows, 1}, R{rows, cols};
    fillSides(top, L, R);

    for(int i = 1; i <= rows; i++)
    {
        for(int j = 1; j <= cols; j++)
        {
            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}

长按识别二维码加好友邀请进信息学竞赛群
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值