资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

牛客:浙江农林大学2022年新生杯程序设计竞赛(同步赛)VP题解-创新互联

五个小时真是折磨,写完直接痿了,站不起来了(bushi 题目链接

在这里插入图片描述

元氏网站建设公司创新互联公司,元氏网站设计制作,有大型网站制作公司丰富经验。已为元氏上1000家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的元氏做网站的公司定做!

1.png

A 打印煎饼(1x)

直接输出

php代码⬇
|       _ ____   _____  _____  |
|      | |  _ \ / ____|/ ____| |
|      | | |_) | |  __| |  __  |
|  _   | |  _<| | |_ | | |_ | |
| | |__| | |_) | |__| | |__| | |
|  \____/|____/ \_____|\_____| |

B 打印煎饼(2x)

将原矩阵的每个字符输出两次,同时每行也输出两次

#includeusing namespace std;

using i64 = long long;

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n,m;
    std::cin >>n >>m;
    for (int i = 0; i< n; i ++) {string s;
        std::cin >>s;
        for (int u = 0; u< 2; u ++) {for (int j = 0; j< m; j ++) {for (int k = 0; k< 2; k ++) {std::cout<< s[j];
                }
            }
            std::cout<< "\n";
        }
    }
    return 0;    
}

C 这个彬彬打起电动超勇的

由于题目数据小,不搞一些花哨操作,直接判断每组寻问中是否有被抓的可能

#includeusing namespace std;

using i64 = long long;

void solve()
{int a,b,c,d;
    std::cin >>a >>b >>c >>d;

    int q;
    std::cin >>q;

    bool ok = false;
    while (q -- ) {int x;
        std::cin >>x;
        if ((x >= a and x<= b) or (x >= c and x<= d)) ok = true;
    }
    if (ok) std::cout<< "Y\n";
    else std::cout<< "N\n";
}

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

D jbgg爆金币咯 题解

1.png

#includeusing namespace std;

#define int long long

void solve()
{int n,m,x;
    std::cin >>n >>m >>x;

    std::vectora(n + 10),b(m + 10),A(x + 10),S(x + 10);

    for (int i = 1; i<= n; i ++) {std::cin >>a[i];
    }

    for (int j = 1; j<= m; j ++) {std::cin >>b[j];
    }

    for (int i = 1; i<= x; i ++) {for (int j = 1; j<= n; j ++) {if (i<= a[j] or S[i - a[j]] == 0) {A[i] = 1;
            }
        }

        for (int j = 1; j<= m; j ++) {if (i<= b[j] or A[i - b[j]] == 0) {S[i] = 1;
            }
        }
    }

    
    if (A[x]) std::cout<< "AsindE\n";
    else std::cout<< "slwang\n";
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

E 视力不好的yyjj

bi为a中下标为i的倍数的元素和,即b1 = a(1-n),b2 = a(2,4…).所以b1包含了a数组的所有元素。 我们可以通过
消除其他项与b1共有的数。如图
6.jpg
要消去b4中的a8,b3中的a6,b2中的a4,a6,a8.最后通过b1便可得出a1

#includeusing namespace std;

#define int long long

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n;
    std::cin >>n;
    std::vectorb(n + 1);

    for (int i = 1; i<= n; i ++) {std::cin >>b[i];
    }

    for (int i = n; i >= 1; i --) {//逆序消
        for (int j = i + i; j<= n; j += i) {b[i] -= b[j];
        }
    }

    std::cout<< b[1]<< "\n";
    return 0;    
}
小细节:枚举bi的时候要逆序枚举,这样消可以省去很多麻烦,附图:

2.png

因惯性思维,没有逆序枚举,导致少考虑一些情况(如消多了)而多WA了3发。以此为诫
F 杨神的命名法

按照题意模拟即可

#includeusing namespace std;

using i64 = long long;

void solve()
{string s;
    std::cin >>s;

    int n = s.size();

    for (int i = 0; i< n; i ++) {if (!i) {s[i] = tolower(s[i]);
            continue;
        }
        if (s[i] >= 'A' and s[i]<= 'Z') {s[i] = tolower(s[i]);
            s[i - 1] = toupper(s[i - 1]);
        }
    }
    s[n - 1] = toupper(s[n - 1]);
    std::cout<< s<< "\n";
}

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

G 汽车人变形

dfs; 明显可以看出答案是一条链,我们应该找到一个入度为0的点进行搜,取搜到的大值即可。
这里直接以每一个点作为根节点搜了起来

#includeusing namespace std;

#define int long long
const int N = 5e3 + 10;
std::vectora(N);
std::vector>>g(N);
std::vectorf(N);
int res = 0;
void dfs(int u,int fa)
{int ans = 0;
    for (auto [k,v] : g[u]) {if (k == fa) continue;
        dfs(k,u);
        res = std::max(res,ans + a[u] + v + f[k]);
        ans = std::max(ans,f[k] + v);
        f[u] = std::max(f[u],ans);
    }

    f[u] += a[u];
    res = std::max(res,f[u]);
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n;
    std::cin >>n;


    for (int i = 1; i<= n; i ++) {std::cin >>a[i];
    }
    for (int i = 1; i< n; i ++) {int a,b,c;
        std::cin >>a >>b >>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }

    dfs(1,1);

    std::cout<< res<< "\n";
    return 0;    
}
匿名函数dfs写完一直报错,调了半小时,所幸直接仍外边了,不知道为啥。很烦!
H 车车的爱之矩阵

一种简单的解法:直接用1和-1构造这个矩阵,容易知道,只有当1和-1交替出现时才能满足题意

#includeusing namespace std;

#define int long long

void solve()
{int n,m;
    std::cin >>n >>m;
    
    for (int i = 1; i<= n; i ++) {for (int j = 1; j<= m; j ++) {std::cout<< ((i + j) % 2 ? "1" : "-1")<< " \n"[j == m];
        }
    }
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}
这里起初是用异或写的,奈何某些地方没有被赋上值。最后没时间了,改了改
I 异或和

I题最后没时间写了,有空再补


J 磊神的慈悲

考虑使用并查集,最后输出每个的祖先

#includeusing namespace std;

#define int long long

const int N = 2e5 + 10;

int pre[N];

int find(int x)
{return x == pre[x] ? pre[x] : pre[x] = find(pre[x]);
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n,m;
    std::cin >>n >>m;

    std::vectora(n + 1);

    for (int i = 1; i< N; i ++) {pre[i] = i;
    }
    for (int i = 1; i<= n; i ++) {std::cin >>a[i];
    }

    while (m --) {int a,b;
        std::cin >>a >>b;
        int fa = find(a);
        int fb = find(b);
        if (fa != fb) {pre[fa] = fb;
        }
    }

    for (int i = 1; i<= n; i ++) {std::cout<< find(a[i])<< " \n"[i == n];
    }
    return 0;    
}
最后输出是一定要再查一下祖先,否则会出现一些点的祖先没有更新过来
K 杨神の签到

数学题,a与a + x互质等价于x 与 a 互质,所以暴力找与x互质的数即可

#includeusing namespace std;

using i64 = long long;

void solve()
{int n;
    std::cin >>n;

    for (int i = 2; ; i ++) {if (__gcd(i,n) == 1) {std::cout<< i<< " "<< i + n<< "\n";
            return;
        }
    }
}

int main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int T;
    std::cin >>T;
    while (T -- ) {solve();
    }
    return 0;    
}

L jbgg想要n

将n拼起来,取模找大值,枚举到m与p的最小值

#includeusing namespace std;

#define int long long

//a^b%p
templateT qmi(T a, int b,T p) {T res = 1 % p;
    while (b)
    {if (b & 1) res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}

signed main()
{std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); 
    int n,m,p;
    std::cin >>n >>m >>p;

    int t = n,c = 0;
    while (t) {t /= 10;
        c ++;
    }
    int w = qmi(1ll * 10,c,p),res = 0;
    for (int i = 1; i<= std::min(m,p); i ++) {t = (t * w + n) % p;
        res = std::max(res,t);
    }

    std::cout<< res<< "\n";
    return 0;    
}

M yyjj 与可恶的工图课

几何题能不能死一死


你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


本文名称:牛客:浙江农林大学2022年新生杯程序设计竞赛(同步赛)VP题解-创新互联
URL链接:http://cdkjz.cn/article/dsiohc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220