牛客周赛 Round 8

A-小美的排列询问_牛客周赛 Round 8 (nowcoder.com)

枚举即可

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int N;
cin >> N;
vector<int> a(N);
for(auto &i : a) cin >>i; int x,y;
cin >> x >> y; for(int i = 1;i < N - 1;i ++){
if(a[i] == x){
if(a[i - 1] == y || a[i + 1] == y){
cout << "Yes\n";
return 0;
}
}else if(a[i] == y){
if(a[i - 1] == x || a[i + 1] == x){
cout << "Yes\n";
return 0;
}
}
} cout << "No\n"; return 0;
}

B-小美走公路_牛客周赛 Round 8 (nowcoder.com)

因为公路是环形的,所以我们可以把公路往后再展开\(N\)个站,然后用一个前缀和和计算两两车站之间的距离,如果是要往前走,那就是用\(sum[y] - sum[x]\),往后走就是\(sum[x+N] - sum[y]\),就可以想象成从\(y\)这个点走过一个环形到达\(x\)站,因为这里都是往前计算的前缀和,所以计算的时候我们要把大的站放前面,小的站放后面

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i ++)
cin >> a[i]; for (int i = 0; i < N; i ++) {
a.push_back(a[i]);
} int x, y;
cin >> x >> y; x--, y--;
if(x > y) swap(y,x);
vector<i64> sum(a.size());
for (int i = 1; i < a.size(); i++)
sum[i] = sum[i - 1] + a[i - 1]; cout << min(sum[y] - sum[x], sum[x + N] - sum[y]) << '\n'; return 0;
}

C-小美的排列构造_牛客周赛 Round 8 (nowcoder.com)

我是直接造了几组数据然后猜了个结论,比如当\(n=6\)时,可以构造一个\(1,6,2,5,3,4\)这样就可以得到\(7,8,7,8,7\),又比如当\(n=5\)时,可以构造\(1,5,2,4,3\),可以得到\(6,7,6,7\),可以肯定的是权值最小都可以得到\(1\),再进一步观察可以发现其实就是将\(1 \sim n\)分成两半,然后后面大的数倒序插入前面

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n;
cin >> n; int m = n / 2; vector<int> b;
while(m){
b.push_back(n);
n--;
m--;
} for(int i = 1;i <= n;i ++){
cout << i << ' ';
cout << b[i - 1] << ' ';
} return 0;
}

D-小美的树上染色_牛客周赛 Round 8 (nowcoder.com)

\(dfs\)每次去搜节点的子孙是否能优先被染红

#include<bits/stdc++.h>

using i64 = long long;

using namespace std;

typedef pair<i64, i64> PII;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n;
cin >> n ;
vector<int> a(n);
for (auto &i : a) cin >> i; vector<vector<int>> g(n);
for (int i = 1, x, y; i < n; i ++) {
cin >> x >> y;
x--, y--;
g[x].push_back(y);
g[y].push_back(x);
} int ans = 0;
vector<bool> v(n, false);
auto dfs = [&](auto self, int x, int u) -> void{
for (auto i : g[x]) {
if (i == u) continue;
self(self, i, x);
int res = a[i] * a[x];
int d = sqrt(res);
if (!v[i] && !v[x] && d * d == res) {
v[i] = v[x] = true;
ans += 2;
}
}
}; dfs(dfs, 0, -1); cout << ans << '\n'; return 0;
}

牛客周赛 Round 8的更多相关文章

  1. 牛客周赛11TG B-弹钢琴

    链接:https://ac.nowcoder.com/acm/contest/941/B来源:牛客网 题目描述 春希想听和纱弹钢琴! 为了阻止异变的发生,Pi将钢琴魔改了 钢琴上有 N 个键,每个键有 ...

  2. 牛客OI周赛9-提高组题目记录

    牛客OI周赛9-提高组题目记录 昨天晚上做了这一套比赛,觉得题目质量挺高,而且有一些非常有趣而且非常清奇的脑回路在里边,于是记录在此. T1: 扫雷 题目链接 设 \(f_i\) 表示扫到第 \(i\ ...

  3. 牛客OI周赛8-提高组A-用水填坑

    牛客OI周赛8-提高组A-用水填坑 题目 链接: https://ac.nowcoder.com/acm/contest/403/A 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制: ...

  4. 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)

    链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  5. 牛客OI周赛7-提高组 A 小睿睿的等式

    链接:https://ac.nowcoder.com/acm/contest/371/A来源:牛客网 小睿睿在游戏开始时有n根火柴棒,他想知道能摆成形如“A+B=n”的等式且使用的火柴棒数也恰好等于n ...

  6. 牛客OI周赛7-提高组 B小睿睿的询问(ST打表)

    链接:https://ac.nowcoder.com/acm/contest/371/B来源:牛客网 小睿睿的n个妹纸排成一排,每个妹纸有一个颜值val[i].有m个询问,对于每一个询问,小睿睿想知道 ...

  7. 牛客OI周赛7-普及组 解题报告

    出题人好评. 评测机差评. A 救救喵咪 二位偏序.如果数据范围大的话直接树状数组,不过才1000就\(O(n^2)\)暴力就ok了. #include <bits/stdc++.h> s ...

  8. 牛客OI周赛2-提高组

    A.游戏 链接:https://www.nowcoder.com/acm/contest/210/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语 ...

  9. 牛客OI周赛10-普及组-A眼花缭乱的街市-(加速+二分)

    https://ac.nowcoder.com/acm/contest/901/A 很简单的一道题,全场只有20+AC,卡时间.新学了cin加速语法和数组二分查找的函数调用. 知道有个读写挂,可以加速 ...

  10. 牛客OI周赛11-普及组 B Game with numbers (数学,预处理真因子)

    链接:https://ac.nowcoder.com/acm/contest/942/B 来源:牛客网 Game with numbers 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C+ ...

随机推荐

  1. Nuxt3 的生命周期和钩子函数(一)

    title: Nuxt3 的生命周期和钩子函数(一) date: 2024/6/25 updated: 2024/6/25 author: cmdragon excerpt: 摘要:本文是关于Nuxt ...

  2. 3568F-翼辉SylixOS国产操作系统演示案例

     

  3. C#中重写(override)及覆盖(new)的区别详解

    1. 重写和覆盖的定义 1.1 重写(override)的定义   在C#中,用override关键字来重写一个父类中的虚方法或抽象方法.override关键字用于指示编译器,我要用派生类中的一个方法 ...

  4. 转-tomcat在控制台打印时乱码

    描述 使用windows的控制台启动tomcat (8.5),Tomcat终端打印出现乱码,在CSDN上找到一个简单有效的解决办法,在此记录. 解决方案 找到Tomcat的根目录下的 /conf/lo ...

  5. CentOS中增加网络连接数的方法

    CentOS默认对外访问,发起的TCP链接总数小于28232个. 可以通过以下命令的结果计算出来 $ cat /proc/sys/net/ipv4/ip_local_port_range 我这里得到的 ...

  6. 自己在本地搭建 git 版本仓库服务器

    请确保你安装了 git 的图形化工具和 git 软件 首先先创建一个目录作为你的项目工程目录,比如 e:/gitTest 其次右键 git init. 然后指定一个 git 服务器目录,例如:e:/g ...

  7. c++17 auto非类型模板参数

    //用auto非类型模板参数 #include <iostream> using namespace std; template<auto c> auto foot() { c ...

  8. vue el-input只能输入正整数 替换e - + 等

    示例:输入分页页数,每页显示条数 <el-input type="number" class="resNums" v-model="item.r ...

  9. 关于SpringBoot中事务回滚没有生效

    在SpringBoot中,事务回滚可以用注解@Transactional标识. Spring声明式事务管理默认对非检查型异常和运行时异常进行事务回滚,而对检查型异常则不进行回滚操作. 1.非检查型异常 ...

  10. docker 容器迁移到其他机器

    docker 容器迁移到其他机器思路为:容器转为镜像,再保存为镜像文件,迁移到其他机器后导入为镜像 1.commit:将容器转镜像 # docker commit {container_id} {镜像 ...