写在前面:

        第三题是我见过的最阴间的模拟题,模拟的时候写了一大串史山,结果点还没拿全,导致最后一题见都没见到。

RC-u1 早鸟价

思路:

        直接按提议模拟即可

AC_CODE:

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    while(n --)
    {
        int m, d, c;
        cin >> m >> d >> c;
        if(m > 7)
        {
            cout << "Too late!" << endl;
            continue;
        }
        else
        {
            if(m == 7 && d > 11) cout << "Too late!" << endl;
            else if(m == 7 && d <= 11 || m == 6 && d > 20)
            {
                if(c == 2000) cout << "Ok!" << endl;
                else if(c < 2000) cout << "Need more!" << endl;
                else cout << "^_^" << endl;
            }
            else 
            {
                if(c == 1800) cout << "Ok!" << endl;
                else if(c < 1800) cout << "Need more!" << endl;
                else cout << "^_^" << endl;
            }
        }
    }
}

RC-u2 谁进线下了?III

思路:

根据题目模拟,比较大于50%场次的时候转成浮点数或者四舍五入一下。

AC_CODE:

#include <iostream>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        int n, s;
        cin >> n >> s;
        int cnt = 0;
        int score = 0;
        for(int i = 1; i <= n; i ++)
        {
            int r, c;
            cin >> r >> c;
            if(r == 1) cnt ++;
            score += c;
        }
        if(cnt >= (n * 0.5)) cout << 1 << " ";
        //煮波这里是转成浮点数了,(int)(n / 2.0 + 0.5) 这是四舍五入的写法
        else cout << 0 << " ";
        if(score - s >= 50) cout << 1 << endl;
        else cout << 0 << endl;
    }
}

RC-u3 点格棋

思路:

        这题更是阴间中的阴间,能不能做对完全靠有没有一双写轮眼。

        首先数据量不大很容易想到开个四维数组,把每个区域标记一下,然后判断一下是不是正方形的最后一笔就可以了,坑点是真多。。。。

分成两类一种是当前画的是横线,第二种是竖线,将四周的坐标表示出来即可判断是不是最后一笔

 

坑点:

只能是横线或者竖线,斜线不行

画过的地方不能再画了

画线位置不能超出范围

画线的曼哈顿距离必须为1(这点没想到痛失7分)

AC_CODE:

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

const int N = 110;

vector<int> wrong; // 存储错误步骤
int st[N][N][N][N];
int sa = 0, sb = 0; // 分数
int last = 1; // 小A先手那上一手就设为小B
int n, m, s;
bool check1(int a, int b, int c, int d, int x) // 竖线时判断是不是最后一笔
{
    if(st[a][b][x][b] && st[c][d][x][d] && st[x][b][x][d])
        return true;
    else return false;
}

bool check2(int a, int b, int c, int d, int y) // 横线时判断是不是最后一笔
{
    if(st[a][b][a][y] && st[c][d][c][y] && st[a][y][c][y])
        return true;
    else return false;
}
void f(int now, int a, int b, int c, int d, int no)
{
    int flag = 0;
    if(now == last) // 顺序错误
    {
        wrong.push_back(no);
        return ;
    }
    if(a < 1 || a > n || c < 1 || c > n || b < 1 || b > m || d < 1 || d > m) // 越界
    {
        wrong.push_back(no);
        return ;
    }
    if(a != c && b != d) // 斜线
    {
        wrong.push_back(no);
        return ;
    }
    if(st[a][b][c][d]) // 重复画线
    {
        wrong.push_back(no);
        return ;
    }

    int dist = max(abs(a - c), abs(b - d));
    if(dist != 1) // 曼哈顿距离不为1
    {
        wrong.push_back(no);
        return ;
    }
    // 横线
    int nx = a - 1;
    if(nx >= 1)
    {
        if(check1(a, b, c, d, nx)) 
        {
            if(now == 0) sa ++;
            else sb ++;
            flag = 1;
        }
    }
    nx = a + 1;
    if(nx <= n)
    {
        if(check1(a, b, c, d, nx))
        {
            if(now == 0) sa ++;
            else sb ++;
            flag = 1;
        }
    }

    //竖线
    int ny = b - 1;
    if(ny >= 1)
    {
        if(check2(a, b, c, d, ny))
        {
            if(now == 0) sa ++;
            else sb ++;
            flag = 1;
        }
    }
    ny = b + 1;
    if(b <= m)
    {
        if(check2(a, b, c, d, ny))
        {
            if(now == 0) sa ++;
            else sb ++;
            flag = 1;
        }
    }

    st[a][b][c][d] = 1;
    st[c][d][a][b] = 1;
    if(flag == 1) last = last; // 如果得分了则连续执行
    else last = now; // 否则换边
}
int main()
{
    cin >> n >> m >> s;
    
    for(int i = 1; i <= s; i ++)
    {
        int now, a, b, c, d;
        cin >> now >> a >> b >> c >> d;
        f(now, a, b, c, d, i);
    }
    if(!wrong.size()) cout << -1 << endl;
    else 
    {
        for(int i = 0; i < wrong.size() - 1; i ++)
        {
            cout << wrong[i] << " ";
        }
        cout << wrong[wrong.size() - 1] << endl;
    }
    if(sa > sb) cout << "0" << " " << sa << endl;
    else cout << "1" << " " << sb << endl;
}

RC-u4 Tree Tree 的

思路:

        保证删除一个节点仍然联通说明这个图是一个环,需要特判一下图中只有两个节点的情况,这种情况下不成环也满足。

        dfs搜索当起点等于终点的时候说明这是一个环,记录节点个数存到ans中,再找出前二大的节点数输出即可,需要特判ans中只有一个值或者为空的情况。

        如果最大的图只有一个节点,第二大只能为0

        如果最大的图没有节点,第二大也没有

        由于图中边最少为0而节点数最少为1,所以当没有边的情况下第一大为1,第二大为0

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

const int N = 55;

vector<int> g[N];
vector<int> ans; // 存储每个环的节点数
int vt[N];

void dfs(int st, int e, int len)
{
    for(auto ed : g[e])
    {
        if(vt[ed]) continue;
        vt[ed] = 1;
        dfs(st, ed, len + 1);
        vt[ed] = 0;
        if(ed == st) ans.push_back(len);
    }
}
int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        int n, m; 
        cin >> n >> m;
        for(int i = 0; i < N; i ++) g[i].clear();
        ans.clear();
        while(m --)
        {
            int a, b;
            cin >> a >> b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        for(int i = 1; i <= n; i ++)
        {
            memset(vt, 0, sizeof vt);
            dfs(i, i, 1);
        }
        sort(ans.begin(), ans.end(), greater<>());
        int last = 0;
        int cnt = 0;
        vector<int> mx;
        for(int i = 0; i < ans.size(); i ++)
        {
            if(ans[i] != last)
            {
                mx.push_back(ans[i]);
                last = ans[i];
                cnt ++;
            }
            if(cnt == 2) break; // 找到前两个最大值
        }
        if(mx.size() < 2) // 判断ans中找不到两个最大的情况
        {
            if(mx.size() == 0) cout << "1 0" << endl; // 最少有1个节点0条边.
            else if(mx[0] > 1) cout << mx[0] << " " << 1 << endl;
            else if(mx[0] == 1) cout << "1 0" << endl;
        }
        else cout << mx[0] << " " << mx[1] << endl;
    }
}

      RC-u5

        学习中...

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐