Codeforces Round 918 (Div. 4)(AK)

A、模拟

B、模拟

C、模拟

D、模拟

E、思维,前缀和

F、思维、逆序对

G、最短路

A - Odd One Out 

    题意:给定三个数字,有两个相同,输出那个不同的数字。

    直接傻瓜写法

void solve() 
{int a , b , c;cin >> a >> b >> c;if(a == b){cout << c << endl;}	else if(a == c){cout << b << endl;}elsecout << a << endl;
}    

 B - Not Quite Latin Square

        题意:给定一个3*3的矩阵,每一行每一列都有且仅有A、B、C三个字母组成。现在给出矩阵中有一个? , 求这个?代表哪个字母。

        可以用二进制表示三个字母是否存在

void solve() 
{string s[3];for(int i = 0 ; i < 3; i ++)cin >> s[i];for(int i = 0 ; i < 3 ;i ++){int mask = 0;for(int j = 0 ; j < 3 ; j ++){mask += (1 << (s[i][j] - 'A')) * (s[i][j] != '?');}if(mask != 7){for(int j = 0 ; j < 3 ; j ++){if((mask >> j) & 1){continue; }else{char c = j + 'A';cout << c <<endl;}}}}
}     

C - Can I Square? 

        题意:给定一个数组,求数组之和能否形成完全平方数。

        注意:直接用sqrt会因为精度问题而出错,所以在[sqrt - 2 , sqrt + 2]之间都试一遍即可。

        

void solve() 
{LL sum = 0;cin >> n;for(int i = 0 ; i < n ; i ++){int x;cin >> x;sum += x;}	LL t = sqrt(sum);for(LL i = t - 1 ; i <= t + 1 ; i ++){if(i < 0)continue;if(i * i == sum){cout <<"YES\n";return;}}cout <<"NO\n";
}    

 D - Unnatural Language Processing 

        题意:

        思路:将a、e看成0,b、c、d看成1。整个单词变成了一个01串,然后发现:当连续的两个1出现时,前一个1需要放到前面的音节结尾。当只有一个连续的1,那么这个1就是音节的开头。然后模拟整个过程就行。

        

// Problem: D. Unnatural Language Processing
// Contest: Codeforces - Codeforces Round 918 (Div. 4)
// URL: https://codeforces.com/contest/1915/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
//10 101
void solve() 
{cin >> n;string s;cin >> s;for(int i = 0 ; i < n ; i ++){if(s[i] == 'a' || s[i] == 'e'){a[i] = 0;}else{a[i] = 1;}}for(int i = 0 ; i < n ; i ++){if(a[i] == 1){cout << s[i];}else if(a[i] == 0){if(i < n - 3){if(a[i + 1] == 1 && a[i + 2] == 1){cout << s[i] << s[i + 1] <<"."; i++;}else{cout << s[i] <<".";}}else if(i == n - 3){cout << s[i] <<".";}else if(i == n - 2){cout << s[i] << s[i + 1];i++;}else{cout << s[i];}}}cout << endl;
}            
int main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}

E - Romantic Glasses 

        题意:给定一数组,求其中是否存在某个连续子序列是否满足\sum _{i = l}^{r}a[i](i\ mod\ 2==0) = \sum _{i = l}^{r}a[i](i\ mod\ 2 == 1)

        思路:转移之后有公式\sum _{i = l}^{r}a[i](i\ mod\ 2==0) + \sum _{i = l}^{r}-a[i](i\ mod\ 2 == 1) = 0,也就是对于原数组的奇数项都乘 -1 之后,求是否存在某个区间之和为0。

        用前缀和sum数组来表示区间,也就是存在sum(r) - sum(l) = 0 , 也就是sum(r) = sum(l)。因此我们可以逐步递增 r,然后看之前是否出现过sum(l)sum(r)相等。可用map或者set来存之前出现过的前缀和情况。这样整个复杂度为O(NlogN)

        

// Problem: E. Romantic Glasses
// Contest: Codeforces - Codeforces Round 918 (Div. 4)
// URL: https://codeforces.com/contest/1915/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
void solve() 
{cin >> n;for(int i = 0 ; i < n ; i ++){cin >> a[i];if(i % 2 == 1){a[i] *= -1;}}	set<int>pre;pre.insert(0);int sum = 0;for(int i = 0 ; i < n ; i ++){sum += a[i];//cout << sum << endl;if(pre.count(sum)){cout <<"YES\n";return;}pre.insert(sum);}cout <<"NO\n";return;
}            
signed main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}

 F - Greetings 

        题意:

        思路:将所有人的起点按照从小到大进行排序,这样就满足了后面的人不会撞到前面的人(只存在后面的人已经到达终点了,然后被前面的人撞)。然后再考虑能够撞多少个人:对于排完序以后的第i个人而言,他能撞到的人是i以后的,终点小于等于b_{i}的人。因此也就是(b_{i} \geq b_{j})(i < j)的个数,也就是按照起点排完序之后的b数组的逆序对数量,然后套一遍逆序对的板子即可。

// Problem: F. Greetings
// Contest: Codeforces - Codeforces Round 918 (Div. 4)
// URL: https://codeforces.com/contest/1915/problem/F
// Memory Limit: 256 MB
// Time Limit: 5000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
int tmp[N];
LL merge_sort(int q[], int l, int r)
{if (l >= r) return 0;int mid = (l + r) >> 1; // 二分区间LL res = merge_sort(q, l, mid) + merge_sort(q, mid + 1, r);//归并int i = l, j = mid + 1, k = 0;while (i <= mid && j <= r){if (q[i] <= q[j]) tmp[k ++] = q[i ++]; // 前面的排序正常,注意`=` 说明不是逆序对else{res += mid - i + 1;tmp[k ++] = q[j ++];}}// 扫尾工作while (i <= mid) tmp[k ++] = q[i ++];while (j <= r) tmp[k ++] = q[j ++];for (int i = l, j = 0; i <= r; i ++ , j ++) q[i] = tmp[j];return res;
}
void solve() 
{cin >> n;pair<int,int>po[n];for(int i = 0 ; i < n ; i++){cin >> po[i].x >> po[i].y;}	sort(po , po + n);int a[n];for(int i = 0 ; i < n ; i ++){a[i] = po[i].y;}LL ans = merge_sort(a , 0 , n  - 1);cout << ans <<endl;
}            
int main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}

 G - Bicycles 

        题意:

       

        思路:观察到数据不大。因此直接考虑最短路算法。需要注意的是,整个过程不仅仅有点这一个条件,还有自行车速度系数这个限制。因此需要将这两个限制都表示出来,具体看代码注释

// Problem: G. Bicycles
// Contest: Codeforces - Codeforces Round 918 (Div. 4)
// URL: https://codeforces.com/contest/1915/problem/G
// Memory Limit: 256 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 1010;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
struct node{int num;int dis;bool operator > (const node &t) const{return dis > t.dis;}int own;
}tmp;
int dis[N][N];//到达i点,且拥有自行车系数j的最短距离
int vis[N][N];//到达i点,且拥有自行车系数j的可能性
vector<node>tr[N];
int cost[N];
void dij(int s)
{for(int i = 1 ; i <= n ; i ++){for(int j = 0 ; j <= 1000 ; j ++){dis[i][j] = llinf;}}priority_queue<node,vector<node> , greater<node> > q;q.push({s , 0 , cost[1]});dis[s][cost[1]] = 0;while(!q.empty()){tmp = q.top();int x = tmp.num;//所在地int y = tmp.own;//拥有的自行车系数q.pop();if(vis[x][y] == 1)continue;vis[x][y] = 1;for(int i = 0 ; i < (int)tr[x].size() ; i ++ ){node now = tr[x][i];int len = tr[x][i].dis;//距离int e = tr[x][i].num;//目标地int pp = min(y , cost[e]);//到达目的地之后所拥有的自行车系数if(dis[e][pp] > dis[x][y] + len * y){dis[e][pp] = dis[x][y] + len * y;q.push({e , dis[e][pp] , pp});}}}
}
void solve() 
{cin >> n >> m;for(int i = 1 ; i <= n ; i ++){tr[i].clear();for(int j = 0 ; j <= 1000 ; j ++){vis[i][j] = 0;}}for(int i = 0 ; i < m ; i ++){int u , v , dis;cin >> u >> v >> dis;tr[u].pb({v , dis , 0});tr[v].pb({u , dis , 0});}for(int i = 1 ; i <= n ; i ++){cin >> cost[i];}dij(1);int ans = llinf;for(int i = 0 ;i <= 1000 ;  i++){ans = min(ans , dis[n][i]);}cout << ans << endl;
}            
signed main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}

        

        

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2660646.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

YOLOv5改进 | 2023主干篇 | 华为最新VanillaNet主干替换Backbone实现大幅度长点

一、本文介绍 本文给大家来的改进机制是华为最新VanillaNet网络&#xff0c;其是今年最新推出的主干网络&#xff0c;VanillaNet是一种注重极简主义和效率的神经网络架构。它的设计简单&#xff0c;层数较少&#xff0c;避免了像深度架构和自注意力这样的复杂操作(需要注意的是…

鸿蒙Harmony(十一)Stage模型

Stage模型&#xff1a;HarmonyOS 3.1 Developer Preview版本开始新增的模型&#xff0c;是目前主推且会长期演进的模型。在该模型中&#xff0c;由于提供了AbilityStage、WindowStage等类作为应用组件和Window窗口的“舞台”&#xff0c;因此称这种应用模型为Stage模型。 UIAb…

verilog rs232串口模块

前面发了个发送模块&#xff0c;这次补齐&#xff0c;完整。 串口计数器&#xff0c;波特率适配 uart_clk.v module uart_clk(input wire clk,input wire rst_n,input wire tx_clk_en,input wire rx_clk_en,input wire[1:0] baud_sel,output wire tx_clk,output wire rx_clk )…

js遍历后端返回的集合将条件相同的放入同一个数组内

项目场景&#xff1a; echarts折线图需要根据条件动态展示多条不同曲线 解决方案&#xff1a; 后端直接将使用sql将数据查询出来返回即可,因为我这里不是Java使用的C#不是很熟练后台不好写逻辑,所以在前端js完成的 代码如下: function createline(villagename, buildingname…

Centos7:Jenkins+gitlab+node项目启动(3)

Centos7&#xff1a;Jenkinsgitlabnode项目启动(1) Centos7&#xff1a;Jenkinsgitlabnode项目启动(1)-CSDN博客 Centos7&#xff1a;Jenkinsgitlabnode项目启动(2) Centos7&#xff1a;Jenkinsgitlabnode项目启动(2)-CSDN博客 Centos7&#xff1a;Jenkinsgitlabnode项目启…

Java ArrayList在遍历时删除元素

文章目录 1. Arrays.asList()获取到的ArrayList只能遍历&#xff0c;不能增加或删除元素2. java.util.ArrayList.SubList有实现add()、remove()方法3. 遍历集合时对元素重新赋值、对元素中的属性赋值、删除元素、新增元素3.1 普通for循环3.2 增强for循环3.3 forEach循环3.4 str…

116基于matlab的盲源信号分离

基于matlab的盲源信号分离。FASTICA方法&#xff0c;能够很好的将信号解混&#xff0c;可以替换数据进行分析。具有GUI界面&#xff0c;可以很好的进行操作。程序已调通&#xff0c;可直接运行。 116matlab盲源信号分离FASTICA (xiaohongshu.com)

20231228在Firefly的AIO-3399J开发板的Android11使用Firefly的DTS配置单前后摄像头ov13850

20231228在Firefly的AIO-3399J开发板的Android11使用Firefly的DTS配置单前后摄像头ov13850 2023/12/28 19:20 缘起&#xff0c;突然发现只能打开前置的ov13850&#xff0c;或者后置的ov13850。 但是不能切换&#xff01; 【SDK&#xff1a;rk3399-android-11-r20211216.tar.xz】…

设备健康管理系统助力制造企业实现数字化转型

在当今快速变革的制造业环境中&#xff0c;数字化转型已成为制造企业保持竞争力和实现可持续发展的关键。在这个数字化转型的浪潮中&#xff0c;设备健康管理系统正发挥着重要的作用。设备健康管理系统通过实时监测、预测分析和智能诊断等功能&#xff0c;为制造企业提供了全面…

Flink实时电商数仓之DWS层

需求分析 关键词 统计关键词出现的频率 IK分词 进行分词需要引入IK分词器&#xff0c;使用它时需要引入相关的依赖。它能够将搜索的关键字按照日常的使用习惯进行拆分。比如将苹果iphone 手机&#xff0c;拆分为苹果&#xff0c;iphone, 手机。 <dependency><grou…

Kubernetes 学习总结(41)—— 云原生容器网络详解

背景 随着网络技术的发展&#xff0c;网络的虚拟化程度越来越高&#xff0c;特别是云原生网络&#xff0c;叠加了物理网络、虚机网络和容器网络&#xff0c;数据包在网络 OSI 七层网络模型、TCP/IP 五层网络模型的不同网络层进行封包、转发和解包。网络数据包跨主机网络、容器…

开箱即用的企业级数据和业务管理中后台前端框架Ant Design Pro 5的开箱使用和偏好配置

Ant Design Pro 介绍 Ant Design Pro 是一个开箱即用的企业级前端解决方案&#xff0c;基于 Ant Design 设计体系&#xff0c;提供了丰富的组件和功能&#xff0c;帮助开发者更快速地开发和部署企业级应用。 Ant Design Pro 使用 React、umi 和 dva 这三个主要的前端开发技术…

elementui+vue2 input输入框限制只能输入数字

方法1 自定义表单校验 <el-form :model"Formdata" ref"formRef" :rules"nodeFormRules" label-width"100px"><el-form-itemlabel"年龄"prop"age"><el-input v-model.number"Formdata.age&q…

HackTheBox-Machines--Photobomb

文章目录 1 端口扫描2 测试思路3 Web漏洞探测4 权限提升 Photobomb 测试过程 1 端口扫描 nmap -sC -sV 10.129.57.2102 测试思路 目标开启了22、80端口&#xff0c;所以测试点还是从80端口开始。 针对80端口的测试&#xff1a;   1.目录扫描   2.网页源代码   3.web漏洞 …

Java开发框架和中间件面试题(10)

目录 104.怎么保证缓存和数据库数据的一致性&#xff1f; 105.什么是缓存穿透&#xff0c;什么是缓存雪崩&#xff1f;怎么解决&#xff1f; 106.如何对数据库进行优化&#xff1f; 107.使用索引时有哪些原则&#xff1f; 108.存储过程如何进行优化&#xff1f; 109.说说…

白话机器学习的数学-1-回归

1、设置问题 投入的广告费越多&#xff0c;广告的点击量就越高&#xff0c;进而带来访问数的增加。 2、定义模型 定义一个函数&#xff1a;一次函数 y ax b &#xff08;a 是斜率、b 是截距&#xff09; 定义函数&#xff1a; 3、最小二乘法 例子&#xff1a; 用随便确定的参…

node 项目中 __dirname / __filename 是什么,为什么有时候不能用?

__dirname 是 Node.js 中的一个特殊变量&#xff0c;表示当前执行脚本所在的目录的绝对路径。 __filename 同理&#xff0c;是 Node.js 中的一个特殊变量&#xff0c;表示当前执行脚本的绝对路径&#xff0c;包括文件名。 在 Node.js 中&#xff0c;__dirname / __filename是…

用通俗易懂的方式讲解大模型:Prompt 提示词在开发中的使用

OpenAI 的 ChatGPT 是一种领先的人工智能模型&#xff0c;它以其出色的语言理解和生成能力&#xff0c;为我们提供了一种全新的与机器交流的方式。但不是每个问题都可以得到令人满意的答案&#xff0c;如果想得到你所要的回答就要构建好你的提示词 Prompt。本文将探讨 Prompt 提…

鸿鹄电子招投标系统:基于Spring Boot、Mybatis、Redis和Layui的企业电子招采平台源码与立项流程

在数字化时代&#xff0c;企业需要借助先进的数字化技术来提高工程管理效率和质量。招投标管理系统作为企业内部业务项目管理的重要应用平台&#xff0c;涵盖了门户管理、立项管理、采购项目管理、采购公告管理、考核管理、报表管理、评审管理、企业管理、采购管理和系统管理等…

elasticsearch系列九:异地容灾-CCR跨集群复制

概述 起初只在部分业务中采用es存储数据&#xff0c;在主中心搭建了个集群&#xff0c;随着es在我们系统中的地位越来越重要&#xff0c;数据也越来越多&#xff0c;针对它的安全性问题也越发重要&#xff0c;那如何对es做异地容灾呢&#xff1f; 今天咱们就一起看下官方提供的…