Codeforces Round 764 (Div. 3)

比赛链接

Codeforces Round 764

  • A. Plus One on the Subset
  • B. Make AP
  • C. Division by Two and Permutation
  • D. Palindromes Coloring
  • E. Masha-forgetful

A. Plus One on the Subset

在这里插入图片描述

Example
input

3
6
3 4 2 4 1 2
3
1000 1002 998
2
12 11

output

3
4
1

题意:

你可以选择多个数字,将其加1。上述操作你可以执行多次。
最终使得数组里的数全部相等
请输出最少操作次数

题解:

需要加最多次的是最小的数到最大的数,所以直接 m a x − m i n max-min maxmin即可

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define int long long
#define end(x) {cout<<x<<endl;return;}
using namespace std;
typedef pair<int,int> PII;
const int N = 2*1e5+10;
string s;char ch;int n;double d;float f;
int a[N],b[N];
void sove(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    cout<<a[n]-a[1]<<endl;
}

signed main(void){
    int _=1;
    cin>>_;
    while(_--)sove();
    return 0;
}

B. Make AP

在这里插入图片描述
Example
input

11
10 5 30
30 5 10
1 2 3
1 6 3
2 6 3
1 1 1
1 1 2
1 1 3
1 100000000 1
2 1 1
1 2 2

output

YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES

题意:

给你一个 a , b , c a,b,c a,b,c。你可以将三个中的任意一个数乘上正整数 m m m,如果最后能形成等差数列,那么就输出"YES",否则输出"NO"

题解:

分别考虑 a ∗ m , b , c a*m,b,c am,b,c a , b ∗ m , c a,b*m,c a,bm,c a , b , c ∗ m a,b,c*m a,b,cm的情况
等差数列就是前两项的差和后两项的差相等情况
就可以得到关于 m = f ( a , b , c ) m=f(a,b,c) m=f(a,b,c)的关系式子,我们只需要判断 m m m是否是正整数即可

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define int long long
#define end {cout<<"YES"<<endl;return;}
using namespace std;
typedef pair<int,int> PII;
const int N = 2*1e5+10;
string s;char ch;int n;double d;float f;
int a[N],b[N];
inline bool check(double x){
    return x==(int )x;
}
void sove(){
   double a,b,c;cin>>a>>b>>c;
    if((2*b-c)/a>0&&check((2*b-c)/a))end
    if((a+c)/(2*b)>0&&check((a+c)/(2*b))) end
    if((2*b-a)/c>0&&check((2*b-a)/c)) end
    cout<<"NO\n";
}

signed main(void){
    int _=1;
    cin>>_;
    while(_--)sove();
    return 0;
}

C. Division by Two and Permutation

在这里插入图片描述
Example
input

6
4
1 8 25 2
2
1 1
9
9 8 3 4 2 7 1 5 6
3
8 2 1
4
24 7 16 7
5
22 6 22 4 22

output

YES
NO
YES
NO
NO
YES

题意:

给你一个数组,你可以多次将数组里的一个数字除二,向下取整,问最终能不能得到一个 1 − n 1-n 1n的排列

题解:

先将数组排序(从大到小),然后大的先降,因为是 1 − n 1-n 1n,所以大于n都需要缩小到 n n n以内,还需要记录 1 − n 1-n 1n的数字出现情况,如果出现过就继续除二,如果最后出现数字变成 0 0 0了,就说明这个数组变不成。

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#define int long long
#define end {cout<<"NO"<<endl;return;}
using namespace std;
typedef pair<int,int> PII;
const int N = 2*1e5+10;
string s;char ch;int n;double d;float f;
int a[N];
bool b[N];
void sove(){
    cin>>n;
    memset(b,false,sizeof(b));
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1,[&](int x,int y){return x>y;});
    bool flag=true;
    for(int i=1;i<=n;i++){
        while(a[i]>n||b[a[i]])a[i]/=2;
        b[a[i]]=true;
        if(!a[i])end
    }
    //for(int i=1;i<=n;i++)if(!b[i])end
    cout<<"YES";
    cout<<endl;

}

signed main(void){
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    cin>>_;
    while(_--)sove();
    return 0;
}

D. Palindromes Coloring

在这里插入图片描述
Example
input

10
8 2
bxyaxzay
6 3
aaaaaa
6 1
abcdef
6 6
abcdef
3 2
dxd
11 2
abcabcabcac
6 6
sipkic
7 2
eatoohd
3 1
llw
6 2
bfvfbv

output

3
2
1
1
1
5
1
1
3
3

题意:

给出长度为 n n n字符串,你可以将其中的若干个字符挑选出来并分成 k k k 组,使每组字符串均为回文串,且这 k k k组字符串中最短的字符串尽可能长。

题解:

记录每个字母出现的次数,然后计算成对出现的和剩余的,因为回文串相当于对称,所以成对出现的就可以有效的增加回文串的长度。
剩下的加上没有用上的配对(成对),如果能大于 k k k组,那就可以增加一个长度(相当于放在回文串的中间!)

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#define int long long
#define end {cout<<"NO"<<endl;return;}
using namespace std;
typedef pair<int,int> PII;
const int N = 2*1e5+10;
string s;char ch;int n;double d;float f;
int a[N];
bool b[N];
void sove(){
    int k;
    cin>>n>>k>>s;
    int num[CHAR_MAX+1]={0};
    for(int i=0;i<s.size();i++)num[s[i]]++;
    int dui=0,sheng=0;
    for(ch='a';ch<='z';ch++){
        dui+=num[ch]/2;
        sheng+=num[ch]%2;
    }
    //cout<<"sheng:"<<sheng<<endl;
    cout<<(dui/k)*2+(sheng+(dui%k)*2>=k)<<endl;

}

signed main(void){
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    cin>>_;
    while(_--)sove();
    return 0;
}

E. Masha-forgetful

在这里插入图片描述
Example
input

5

4 8
12340219
20215601
56782022
12300678
12345678

2 3
134
126
123

1 4
1210
1221

4 3
251
064
859
957
054

4 7
7968636
9486033
4614224
5454197
9482268

output

3
1 4 1
5 6 2
3 4 3
-1
2
1 2 1
2 3 1
-1
3
1 3 2
5 6 3
3 4 1

题意:

给出 n n n, m m m,表示有 n n n个长度为 m m m的字符串
再给出一个字符串 s s s
题目是按照电话的记忆来讲的,实际上就是:
你可以在 n n n个字符串里面截取多个长度大于2的字串,将字串拼接能合成为字符串 s s s
输出截取字串个数和字串位置( l , r , i l,r,i l,r,i i i i表示在哪一个字符串, [ l , r ] [l,r] [l,r]表示位置左端点和右端点))
如果不能输出-1

当场写的:

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#define int long long
#define end {cout<<-1<<endl;return;}
using namespace std;
typedef pair<int,int> PII;
const int N = 2*1e5+10;
string s[N];char ch;int n,m;double d;float f;
//int a[N];
//bool b[N];
void sove(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>s[i];
    string string1;cin>>string1;
    int ans=0;
    vector<tuple<int,int,int>>v;
    int string1_i=0;
    for(int i=1;i<=n;i++){
        int flag=0,first=-1,last=-1;
        int go_end=0;
        for(int j=0;j<s[i].size();j++){
            if(s[i][j]==string1[string1_i]){
                flag++;
                if(flag==1)first=j;
                string1_i++;
                if(string1_i==string1.size()){
                    if(j-first>=1)
                    {
                        v.push_back({first+1, j+1, i});//last
                        go_end=1;
                        break;
                    }
                    else {
                        //还原
                        string1_i--;
                        flag=0;
                        continue;
                    }
                }
            }
            else if(flag){
                last=j-1;
               //input
               if(last-first>=1)
               v.push_back({first+1,last+1,i});
               else {
                   //还原
                   string1_i--;
                   flag=0;
                   continue;
               }
               flag=0;
               j=0;
               //i=1; //不加,最后一个测试没过,加了 需要判的 -1 全错
               //ok //缘由:每个这样的段必须有长度至少2
               i=1;
            }
        }
        if(go_end)break;
    }
    if(string1_i!=string1.size()) end
    else{
        ans=(int)v.size();
        cout<<ans<<endl;
        for(int i=0;i<v.size();i++){
            cout<<get<0>(v[i])<<' '<<get<1>(v[i])<<' '<<get<2>(v[i])<<endl;
        }
    }

}

signed main(void){
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    cin>>_;
    while(_--)sove();
    return 0;
}

感觉是还原那边有点问题,如果另一个地方有长度大于2的字串还包含了现在判断的字符,那么其实就需要还原多个了。。。

offical:

#include <bits/stdc++.h>

using namespace std;
const int N = 1e4;
map<string, bool> have;
map<string, tuple<int,int,int>> pos;

void solve() {
    int n, m; cin >> n >> m;
    vector<bool> dp(m+1, false);
    vector<int> pr(m+1);
    vector<string> cache;
    dp[0] = true;

    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < m; j++) {
            string t;
            t += s[j];
            for(int k = 1; k <= 2; k++) {
                if (k + j >= m) break;
                t += s[j+k];

                if (!have[t]) {
                    have[t] = true;
                    pos[t] = make_tuple(j, j+k, i);
                    cache.push_back(t);
                }
            }
        }
    }

    string s; cin >> s;
    for (int i = 0; i < m; i++) {
        string t;
        t += s[i];
        for (int k = 1; k <= 2; k++) {
            if (i - k < 0) break;
            t = s[i-k] + t;
            if (have[t] && dp[i-k]) {
                dp[i+1] = true;
                pr[i+1] = i-k;
            }
            if (dp[i+1]) break;
        }
    }
    for (string t : cache) {
        have[t] = false;
    }

    if (!dp[m]) {
        cout << "-1\n";
        return;
    }
    vector<tuple<int,int,int>> ans;

    for (int k = m; k > 0; ) {
        int p = pr[k];
        string t = s.substr(p, k - p);
        ans.emplace_back(pos[t]);
        k = p;
    }

    cout << (int)ans.size() << '\n';
    reverse(ans.begin(), ans.end());
    for (auto [l,r,i] : ans) cout << l+1 << ' ' << r+1 << ' ' << i+1 << '\n';
}

int main() {
    int t;
    cin >> t;
    for (int tt = 0; tt < t; tt++) {
        solve();
    }
}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

计算机网络考试多选题汇总Ⅱ

https://cadyin.blog.csdn.nethttps://blog.csdn.net/qq_38639612?spm1010.2135.3001.5421 计算机网络考试多选题汇总 1、在Windows中&#xff0c;任务管理器的作用是() A&#xff0e;终止未响应的应用程序 B&#xff0e;终止进程的运行 C&#xff0e;查看系统当前的信息 …

车载网络测试 - CANCANFD - 基础篇_01

目录 问题思考&#xff1a; 一、为什么需要总线? 二、什么是CAN总线? 三、为什么是CAN总线? 四、曾经的车用总线 1、SAEJ1850(Class2) 2、SAEJ1708 3、K-Line 4、BEAN 5、 byteflight, K-Bus 6、D2B 五、当前的车用总线 1、CAN 2、LIN 3、FlexRay 4、MOST 六…

python-sqlite3使用指南

python下sqlite3使用指南 文章目录 python下sqlite3使用指南开发环境sqlite3常用APICRUD实例参考 开发环境 vscode ​ 开发语言&#xff1a; python vscode SQLite插件使用方法&#xff1a; 之后在这里就可以发现可视化数据&#xff1a; sqlite3常用API Python 2.5.x 以上…

E往无前 | 腾讯云大数据 ElasticSearch 高级功能:Cross Cluster Replication实战

前言 Elasticsearch在platinum版本中&#xff0c;推出了Cross Cluster Replication特性&#xff08;以下简称CCR&#xff09;&#xff0c;也即跨集群远程复制。 该特性可以解决两类问题&#xff1a; 1&#xff0c;数据迁移&#xff1b; 2&#xff0c;异地备份。 本文以实战为主…

微服务和领域驱动

一、微服务 1.1 什么是微服务 微服务就是一些协同工作的小而自治的服务。 关键词&#xff1a; 小而自治 -- 小 “小”这个概念&#xff0c;一方面体现在微服务的内聚性上。 内聚性也可以称之为单一职责原则&#xff1a;“把因相同原因而变化的东西聚合到一起&#xff0c;…

企业电子招投标采购系统源码之登录页面-java spring cloud

​ 信息数智化招采系统 服务框架&#xff1a;Spring Cloud、Spring Boot2、Mybatis、OAuth2、Security 前端架构&#xff1a;VUE、Uniapp、Layui、Bootstrap、H5、CSS3 涉及技术&#xff1a;Eureka、Config、Zuul、OAuth2、Security、OSS、Turbine、Zipkin、Feign、Monitor、…

202312读书笔记|《赶时间的人》——灰暗的从前会成为照亮未来的光,艰难的生活里,诗歌是那陡峭的另一面

202312读书笔记|《赶时间的人》——灰暗的从前会成为照亮未来的光&#xff0c;艰难的生活里&#xff0c;诗歌是那陡峭的另一面 《赶时间的人》 作者王计兵&#xff0c;一个外卖员的诗&#xff0c;饱含对生活的热情&#xff0c;向上的力量&#xff0c;仿若身在炼狱&#xff0c;心…

【计算机网络】3、IO 多路复用:select、poll、epoll、reactor | 阻塞非阻塞、同步异步

文章目录 一、select()1.1 用法1.1 实战 二、poll()2.1 用法2.2 实战 三、阻塞、非阻塞3.1 非阻塞 IO3.1.1 read()3.1.2 write()3.1.3 accept()3.1.4 connect()3.1.5 非阻塞IO select() 多路复用实战 四、epoll()4.1 epoll_create()4.2 epoll_ctl()4.3 epoll_wait()4.4 实战4.…

Dubbo源码篇07---SPI神秘的面纱---原理篇---下

Dubbo源码篇07---SPI神秘的面纱---原理篇---下 引言根据name获取扩展实例对象获取默认扩展实例对象按条件批量获取扩展实例对象实例演示 小结 引言 上篇文章&#xff1a; Dubbo源码篇06—SPI神秘的面纱—原理篇—上 我们追踪了getAdaptiveExtension获取自适应扩展点的整个流程…

(常见)数据模型

文章目录 数据模型概述一、数据模型概要1.模型、建模与抽象2.数据模型3.两类数据模型 二、数据库模型的组成要素1.数据结构2.数据操作3.数据的完整性约束 三、概念模型1.概要2.基本概念3.概念模型的表示方法 常用数据模型一、层次模型1.简介2.数据结构3.数据操纵与完整性约束4.…

【ZYNQ】ZYNQ7000 UART 控制器及驱动应用示例

UART 简介 我们在使用 PS 的时候&#xff0c;通常会添加 UART 控制器&#xff0c;用于打印信息和调试代码。除此之外&#xff0c;PS 在和外 部设备通信时&#xff0c;也会经常使用串口进行通信。 UART 控制器 UART 控制器是一个全双工异步收发控制器&#xff0c;ZYNQ 内部包…

教你一步步使用实现TensorFlow 进行对象检测

在本文中,我们将学习如何使用 TensorFlow Hub 预训练模型执行对象检测。TensorFlow Hub 是一个库和平台,旨在共享、发现和重用预训练的机器学习模型。TensorFlow Hub 的主要目标是简化重用现有模型的过程,从而促进协作、减少冗余工作并加速机器学习的研发。用户可以搜索社区…

Linux内核源码分析-进程调度(五)-组调度

出现的背景 总结来说是希望不同分组的任务在高负载下能分配可控比例的CPU资源。为什么会有这个需求呢&#xff0c;假设多用户计算机系统每个用户的所有任务划分到一个分组中&#xff0c;A用户90个任务&#xff0c;而B用户只有10个任务&#xff08;这100个任务假设都是优先级一…

Python 下载的 11 种姿势,一种比一种高级

今天我们一起学习如何使用不同的Python模块从web下载文件。此外&#xff0c;你将下载常规文件、web页面、Amazon S3和其他资源。 通过本文的学习&#xff0c;你将学到如何克服可能遇到的各种挑战&#xff0c;例如下载重定向的文件、下载大型文件、完成一个多线程下载以及其他策…

C# WPF窗体设计器显示以及App.xaml文件打不开(VS 2022)

问题描述&#xff1a; 在项目中遇到了App.xaml设计器打不开以及窗体设计器不显示&#xff0c;只有代码&#xff0c;如图所示&#xff1a; 可以明显的看见左下角的设计器不见&#xff0c;但是用户控件又有设计器 解决方法&#xff1a; (一、App.xaml不能正常打开) ①清理项…

定薪17K*15,阿里测开岗上岸面经分享....

先简单介绍一下我自己吧&#xff0c;等会大家以为我是什么学历狂人&#xff0c;技术大牛&#xff0c;我毕业于广东一个普通本科院校&#xff0c;绝对不是什么双一流大学&#xff0c;大家不要有距离感&#xff0c;这也是我为什么来分享的原因&#xff0c;因为我觉得我这段经验还…

硬件软件【部署】

开发板和主机 1.功能不同&#xff1a;帮助开发者进行嵌入式系统的开发和调试&#xff0c;具有较强的硬件拓展能力&#xff0c;可以连接各种传感器/执行器等外设。主机为满足一般的计算需求而设计&#xff0c;具备更强的计算和图形处理能力。 2.架构不同&#xff1a;开发板通常…

【接口测试】JMeter测试WebSocket接口

目录 一、WebSocket简介 二、JMeter测试WebSocket接口 三、WebSocket和Socket的区别 最近老被问到WebSocket&#xff0c;突然想到以前大学时上Java课的时候&#xff0c;老师教我们socket连接&#xff0c;一个同学电脑做客户端&#xff0c;一个同学电脑做服务端&#xff0c;…

LAMP平台搭建

文章目录 LAMP概述安装apache安装mysql安装php LAMP概述 LAMP架构是目前成熟的企业网站应用模式之一&#xff0c;指的是协同工作的一整套系统和相关软件&#xff0c;能够提供动态Web站点服务及其应用开发环境。LAMP是一个缩写词&#xff0c;具体包括Linux操作系统、Apache网站…

Java --- 期末复习卷

一、单选题 1&#xff0e;所有Java应用程序主类必须有一个名叫( )的方法。[ ] A&#xff0e;method B&#xff0e;main() C&#xff0e;java() D&#xff0e;hello 2&#xff0e;编写并保存了一个Java程序文件之后&#xff0c;( )它。[ …
最新文章