第一届“成都信息工程大学团体程序设计天梯赛“ 正式赛补题

太菜了QAQ,好多模棱两可的算法,要是掌握说不定会上200分
还有一个就是速度提不上去,遇到大模拟真的会耗时,还是敲的少了
L1-8 天梯赛团队总分 (20 分)
模拟,当时知道自己在多次提交取最大值这块没处理,只是没反应过来,下来用结构体里面存一个二维数组完美解决

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
struct score
{
    int id, num0, num1, num2, num11, num22, sum;
    int gra[10][10];
    bool operator<(const score t) const
    {
        if (sum == t.sum)
            return id < t.id;
        else
            return sum > t.sum;
    }
} sc[N], team;
struct shu
{
    int x, y;
    char ss[222][20];
} shu[N];
int n, cnt;
int a[N][N];
char s[222][20];
int main()
{
    IOS;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> s[i] >> y;
        int xx = s[i][1] - '0', yy = s[i][3] - '0'; ///
        sc[x].gra[xx][yy] = max(sc[x].gra[xx][yy], y);
    }
    for (int i = 1; i <= 5; i++)
    {
        for (int j = 1; j <= 3; j++)
            for (int k = 1; k <= 8; k++)
            {
                // printf("%d  ", sc[i].gra[j][k]);
                if (j == 1)
                    sc[i].num0 += sc[i].gra[j][k];
                else if (j == 2)
                    sc[i].num1 += sc[i].gra[j][k];
                else
                    sc[i].num2 += sc[i].gra[j][k];
            }
    }
    for (int i = 1; i <= 5; i++)
    {
        if (sc[i].num0 > 60)
            sc[i].num11 += sc[i].num1;
        if (sc[i].num11 > 25)
            sc[i].num22 += sc[i].num2;
        team.num0 += sc[i].num0;
        team.num1 += sc[i].num1;
        team.num2 += sc[i].num2;
        sc[i].sum = sc[i].num0 + sc[i].num11 + sc[i].num22;
        sc[i].id = i;
    }
    if (team.num0 > 300)
        team.num11 = team.num1;
    if (team.num11 > 125)
        team.num22 = team.num2;
    cout << team.num0 + team.num11 + team.num22 << endl;
    sort(sc + 1, sc + 1 + 5);
    for (int i = 1; i <= 5; i++)
        cout << sc[i].id << " " << sc[i].sum << endl;
    return 0;
}

L2-2 走马 (25 分)
BFS,但是因为对bfs的不熟练不自信 ,没搞出来

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int n, m, stax, stay;
int dis[N][N];
bool vis[N][N];
typedef struct point
{
    int x, y;
} point;
bool check(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= n; }
void bfs(point aim)
{
    queue<point> q;
    q.push(aim);
    vis[aim.x][aim.y] = 1;
    dis[aim.x][aim.y] = 0;
    while (q.size())
    {
        point v = q.front();
        q.pop();
        for (int i = 0; i < 8; i++)
        {
            int nex = v.x + dx[i], ney = v.y + dy[i];
            if (check(nex, ney))
            {
                if (vis[nex][ney])
                    continue;
                vis[nex][ney] = 1;
                q.push({nex, ney});
                dis[nex][ney] = dis[v.x][v.y] + 1;
            }
        }
    }
}
signed main()
{
    cin >> n >> stax >> stay;
    memset(dis, -1, sizeof dis);
    bfs({stax, stay});
    cout << dis[1][1] << endl;
    cout << dis[1][n] << endl;
    cout << dis[n][1] << endl;
    cout << dis[n][n] << endl;
}

L2-3 区间质数 (25 分)
这题数据是真的水,试除法求素数也能过,我是为了纪念一下欧拉筛,当时扣6分是因为这题还考了前缀和,寄

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int cnt, T, res;
int prim[N], ans[N];
bool isprim[N];
void Prim()
{
    memset(isprim, 1, sizeof isprim);
    isprim[0] = isprim[1] = 0;
    for (int i = 2; i <= N; i++)
    {
        if (isprim[i])
            prim[cnt++] = i;
        for (int j = 0 && j < cnt; i * prim[j] <= N; j++)
        {
            isprim[i * prim[j]] = 0;
            if (i % prim[j] == 0)
                break;
        }
    }
}
int main()
{
    IOS;
    Prim();
    for (int i = 1; i <= N; i++)
    {
        if (isprim[i])
            ans[i] = ans[i - 1] + 1;
        else
            ans[i] = ans[i - 1];
    }
    cin >> T;
    while (T--)
    {
        int l, r;
        cin >> l >> r;
        cout<<ans[r]-ans[l-1]<<endl;
    }
    return 0;
}

L3-1 收集纪念币 (30 分)
状压dp,属于是位运算了,具体一点是hamilton问题

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
#define IOS ios::sync_with_stdio(0), cin.tie(0)
int n, h, res;
int dp[(1 << 20) + 5][20], val[25][25]; ///加减运算级高于移位
int hamilton()
{ ///dp[i][j]表示状态为i时候,到达了第j个点
    memset(dp, 0x3f, sizeof dp);
    dp[1][0] = 0; ///位运算从0开始比较好算一点
    for (int i = 0; i <= (1 << n); i++)
        for (int j = 0; j < n; j++)
            if ((i >> j) & 1)
                for (int k = 0; k < n; k++)
                    if ((i ^ (1 << j)) >> k & 1)
                        dp[i][j] = min(dp[i][j], dp[i ^ (1 << j)][k] + val[k][j]);
    return dp[(1 << n) - 1][n - 1]; ///即n为全是1的状态,这时候到达了n-1这个点
}
signed main()
{
    IOS;
    cin >> n >> h;
    for (int i = 1; i <= n * (n - 1) / 2; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        val[u - 1][v - 1] = w;
        val[v - 1][u - 1] = w;
    }
    res = hamilton();
    if (h > res)
    {
        // printf("Yes\n");///这个输出会位置颠倒
        cout << "Yes" << endl;
        cout << h - res << endl;
    }
    else
    {
        cout << "No" << endl;
        cout << res - h + 1 << endl;
    }
}

待更···

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

WTcrazy _

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

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

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

打赏作者

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

抵扣说明:

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

余额充值