牛客:浙江农林大学2022年新生杯程序设计竞赛(同步赛)VP题解-创新互联
                                            
                                                五个小时真是折磨,写完直接痿了,站不起来了(bushi 
题目链接
B 打印煎饼(2x)
C 这个彬彬打起电动超勇的
D jbgg爆金币咯 题解
E 视力不好的yyjj
F 杨神的命名法
G 汽车人变形
H 车车的爱之矩阵
I 异或和
J 磊神的慈悲
K 杨神の签到
L jbgg想要n
M yyjj 与可恶的工图课
                
     
文章名称:牛客:浙江农林大学2022年新生杯程序设计竞赛(同步赛)VP题解-创新互联
链接地址:http://www.scyingshan.cn/article/dsiohc.html
                                            
                                        


直接输出
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爆金币咯 题解

#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共有的数。如图
要消去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;    
}
  
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;    
}
    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题解-创新互联
链接地址:http://www.scyingshan.cn/article/dsiohc.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 