School training competition ( Second )

A. Medium Number

链接 : Problem - 1760A - Codeforces

 就是求三个数的中位数 : 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){int a[3];for(int i=0;i<3;i++) cin >> a[i];sort(a,a+3);cout << a[1] << endl;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

B. Atilla's Favorite Problem

 就是求最大字母的长度 (与a的距离)

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;int n ;
string s;inline void solve(){cin >> n ;cin >> s;sort(s.begin(),s.end());int ans = (int)(s[n-1]-'a'+1);cout << ans << endl;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

  C. Advantage

链接 : Problem - 1760C - Codeforces

数据范围小的话,随便弄,直接排序之后,求出最大和第二大的值,然后遍历i,求a[i]与除a[i]之外最大值的差距。

 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;int n ;inline void solve(){cin >> n;vector<int> a(n),b(n);for(int i=0;i<n;i++){cin >> b[i];a[i] = b[i];}sort(b.begin(),b.end());int ma = b[n-1] , mi = b[n-2];for(int i=0;i<n;i++){if(a[i] != ma) cout << a[i] - ma << " ";else cout << a[i] - mi << " ";}cout << endl;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

D. Challenging Valleys

链接 : Problem - 1760D - Codeforces

 题目大概就是说 给出一个数组,如果该数组有且仅有 一个山谷形状的子数组,就输出yes,否则返回false;

这题直接模拟就可以了

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;int n;
int a[N],b[N];inline void solve(){cin >> n;for(int i=0;i<n;i++) cin >> b[i];if(n==1){cout << "YES" << endl;return ;	}int len = n;n = 0;a[n++] = b[0];//把连续的数去重for (int i = 1; i < len; ++i) {if (b[i] != b[i - 1])a[n++] = b[i];}int cnt = 0;if(n==1 || n==2){cout << "YES" << endl;return ;}if(a[1]>a[0]) cnt ++;if(a[n-2] > a[n-1]) cnt ++;for(int i=1;i<n-1;i++){if(a[i-1]>a[i] && a[i] < a[i+1]){cnt ++;}}if(cnt == 1) cout << "YES" << endl;else cout << "NO" << endl;return ;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

E. Binary Inversions

链接 : Problem - 1760E - Codeforces

思路 : 要求逆序对的数量最大,那么也就只有三种情况,不改 / 将第一个0改为1 / 将最后的1转换为0, 三种情况分情况讨论即可;

 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){int n ; cin >> n;LL ans = 0 , res = 0;vector<int> a(n);for(int i=0;i<n;i++) cin >> a[i];int pre = 0;for(int i=n-1;i>=0;i--){if(a[i]==0) pre++;else ans += pre; // 预处理每个 1 后面 有 多少个 0 之和  }pre = 0;int t = -1;for(int i=0;i<n;i++){if(a[i]==0){// 将第一个 0 转换为 1 t = i;a[i]=1;break;}}for(int i=n-1;i>=0;i--){if(a[i]==0) pre++;else res += pre;}ans = max(ans,res);if(t!=-1) a[t] = 0;res = 0;pre = 0;for(int i=n-1;i>=0;i--){if(a[i]==1){ // 将最后的 1 转换为 0 a[i]=0;break;}}for(int i=n-1;i>=0;i--){if(a[i]==0) pre++;else res += pre;}cout << max(res,ans) << endl;return ;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

F. Quests

链接 : Problem - 1760F - Codeforces

 

思路 :  二分求 k 值

/**
*  ┏┓   ┏┓
* ┏┛┻━━━┛┻┓
* ┃       ┃
* ┃   ━   ┃ 
*  ████━████
*  ◥██◤ ◥██◤ 
* ┃   ┻   ┃
* ┃       ┃ 
* ┗━┓ Y  ┏━┛
*   ┃ S  ┃ 
*   ┃ S  ┃ 
*   ┃    ┗━━━┓ 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ 
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛
*/#include<bits/stdc++.h>
using namespace std;#define int long long
int n,c,d;
int T;
int a[1000050];inline bool check(int k){int now = 1;int res = 0;for(int i=1;i<=d;++i){res+=a[now];++now;if(now == k+2){now = 1;}if(now == n +1){i += k + 1 - n;now = 1;}}return res >= c;
}signed main()
{cin >> T ;while(T--) {cin >> n >> c >> d;for(int i=1; i<=n; ++i) cin >> a[i] ;int sum = 0;sort(a+1,a+n+1);reverse(a+1,a+n+1);bool  f = 0;if(a[1] * d < c){puts("Impossible");continue;}if(d <= n){sum = 0;for(int i=1;i<=d;++i){sum+=a[i];}if(sum >= c){f = 1;}}if(f){puts("Infinity");continue;}int res = 0;int  l =0;int  r =1e16+1;while(l<=r){int mid = l + r >> 1;if(check(mid)){res = mid;l = mid + 1;}else{r = mid - 1;}}if(res == 1e16 + 1){puts("Infinity");continue;}cout<<res<<endl;}return 0;
}

A - Filter

链接 : A - Filter

直接模拟就行了

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){int n ; cin >> n;for(int i=0;i<n;i++){int x ; cin >> x;if(x %2 ==0){cout << x << " ";}}
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}

B - ASCII Art

链接 : B - ASCII Art

也是水题,直接模拟输出即可

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 110;int a[N][N];
char s[N][N];inline void solve(){int n,m ;cin >> n >> m;for(int i=0;i<n;i++)for(int j = 0;j<m;j++)cin >> a[i][j];for(int i=0;i<n;i++)for(int j = 0;j<m;j++){if(a[i][j] == 0) s[i][j] = '.';else s[i][j] = (char)('A'+a[i][j]-1);}for(int i=0;i<n;i++){for(int j = 0;j<m;j++){cout << s[i][j];		}cout << endl;}
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}

C - Merge Sequences

链接 : C - Merge Sequences

题意大概是合并两个升序排列的数组,然后求a,b两个数组的元素在新数组中的下标是多少:

这一题直接模拟合并过程即可,在合并的过程中将对应的下标分别添加到ca,cb两个数组中; 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;const int N = 1e5+10;
int a[N],b[N];int n,m;inline void solve(){cin >> n >> m;for(int i=1;i<=n;i++) cin >> a[i];for(int i=1;i<=m;i++) cin >> b[i];// a , b 递增 vector<int> ca,cb; int k = 1 ;int p1 = 1 , p2 = 1;while(p1 <= n || p2 <= m){if(p1 == n+1){cb.push_back(k++);p2++;}else if(p2 == m+1){ca.push_back(k++);p1++;}else if(a[p1] < b[p2]){ca.push_back(k++);p1++;}else{cb.push_back(k++);p2++;}}for(int x : ca) cout << x << " ";cout << endl;for(int x : cb) cout << x << " ";cout << endl;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}

D - Bank

链接 : D - Bank

思路 : 模拟

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 5e5+10;int n,q;
int t,x;
bool a[N] = {false}; // 标记 是不是已经 go inline void solve(){cin >> n >> q;int cnt = 1 , now = 1;while(q--){cin >> t;if(t==1){cnt ++;}else if(t==2){cin >> x;// 叫到就一定来了 a[x] = true;}else{while(a[now]) ++now;cout << now << endl;}}
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}

E - 2xN Grid

链接 : E - 2xN Grid

思路 : 也是模拟 , 一一对应即可,和 C 题类似

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 1e5+10;LL l,n,m;
LL v1[N],len1[N];//值 和 个数 
LL v2[N],len2[N];inline void solve(){cin >> l >> n >> m;for(int i=1;i<=n;i++) cin >> v1[i] >> len1[i];for(int i=1;i<=m;i++) cin >> v2[i] >> len2[i];LL ans = 0;int a = 1 , b = 1;while(a <= n && b <= m){if(v1[a] == v2[b]) ans += min(len1[a] , len2[b]);if(len1[a] < len2[b]){len2[b] -= len1[a];a++;}else{len1[a] -= len2[b];b++;}}cout << ans << endl;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java线程同步

认识线程同步 解决方案 方法一&#xff1a;同步代码块 package com.itheima.d3;public class ThreadTest {public static void main(String[] args) {Accout acc new Accout("ICBC-110",100000);new DrawThread(acc,"小明").start();//小明new DrawThread…

鼎盛合:如何做一个车载便携吸尘器方案

汽车是我们日常生活中极为重要的交通工具&#xff0c;随着我们生活水平的提高自然而然地对汽车的要求也在相对提高&#xff0c;尤其是对汽车内部清洁更是引起许多有车人士的注意。如车载吸尘器深受大家的喜爱这一点就可见对汽车内部清洁的重视。 车载吸尘器是一个用于汽车清洁的…

Qt::Window 、Qt::Tool是 Qt 框架中的一个窗口标志(Window Flag),用于指定窗口的类型和行为

Qt::Window Qt::Window 是 Qt 框架中的一个窗口标志&#xff08;Window Flag&#xff09;&#xff0c;用于指定窗口的类型和行为。 在 Qt 中&#xff0c;窗口标志用于控制窗口的外观、行为和交互方式。通过使用不同的窗口标志组合&#xff0c;可以定制窗口的特性&#xff0c;…

Python实现DDos攻击实例详解

文章目录 SYN 泛洪攻击Scapy3k 基本用法代码实现DDos 实现思路argparse 模块socket 模块代码实现Client 端程序测试后记关于Python技术储备一、Python所有方向的学习路线二、Python基础学习视频三、精品Python学习书籍四、Python工具包项目源码合集①Python工具包②Python实战案…

Kotlin学习——kt里的集合,Map的各种方法之String篇

Kotlin 是一门现代但已成熟的编程语言&#xff0c;旨在让开发人员更幸福快乐。 它简洁、安全、可与 Java 及其他语言互操作&#xff0c;并提供了多种方式在多个平台间复用代码&#xff0c;以实现高效编程。 https://play.kotlinlang.org/byExample/01_introduction/02_Functio…

C++——vector插入与删除和数据存取

一. vector插入和删除 功能描述:对vector容器进行插入、删除操作 函数原型: push back(ele); //尾部插入元素ele pop_back(); //删除最后一个元素 insert(const iterator pos, el…

MFC 读写注册表

在MFC (Microsoft Foundation Classes) 中读写注册表涉及到使用 CRegKey 类&#xff0c;这个类提供了一组方法来操作Windows注册表。以下是如何使用MFC来读取和写入注册表值的基本步骤&#xff1a; 写入注册表值 创建或打开注册表项: 使用 CRegKey::Create 或 CRegKey::Open 方…

LuatOS-SOC接口文档(air780E)--rsa - RSA加密解密

示例 -- 请在电脑上生成私钥和公钥, 当前最高支持4096bit, 一般来说2048bit就够用了 -- openssl genrsa -out privkey.pem 2048 -- openssl rsa -in privkey.pem -pubout -out public.pem -- privkey.pem 是私钥, public.pem 是公钥 -- 私钥用于 加密 和 签名, 通常保密, 放在…

acwing算法基础之动态规划--背包问题

目录 1 基础知识2 模板3 工程化 1 基础知识 &#xff08;零&#xff09; 背包问题描述&#xff1a;有 N N N个物品&#xff0c;每个物品的体积是 v i v_i vi​&#xff0c;价值是 w i w_i wi​&#xff0c;现有容量是 V V V的背包&#xff0c;求这个背包能装下的物品的最大价值…

C#中的警告CS0120、CS0176、CS0183、CS0618、CS0649、CS8600、CS8601、CS8602、CS8604、CS8625及处理

目录 一、CS0120 二、CS0176 1.解决前 2.解决后 3.解决办法 三、CS0183 四、CS0618 五、CS8600 六、CS8602 七、CS8622 1. 解决前&#xff1a; 2. 解决后&#xff1a; 3.解决方法&#xff1a; 八、CS8604和CS8625 九、CS0649 十、CS8601 一、CS0120 严重性 代…

【算法萌新闯力扣】:回文链表

力扣题目&#xff1a;回文链表 开篇 今天是备战蓝桥杯的第23天。我加入的编程导航算法通关村也在今天开营啦&#xff01;那从现在起&#xff0c;我的算法题更新会按照算法村的给的路线更新&#xff0c;更加系统。大家也可以关注我新开的专栏“算法通关村”。里面会有更全面的知…

pandas教程:Techniques for Method Chaining 方法链接的技巧

文章目录 12.3 Techniques for Method Chaining&#xff08;方法链接的技巧&#xff09;1 The pipe Method&#xff08;pipe方法&#xff09; 12.3 Techniques for Method Chaining&#xff08;方法链接的技巧&#xff09; 对序列进行转换的时候&#xff0c;我们会发现会创建很…

操作系统的中断与异常(408常考点)

为了进行核心态和用户态两种状态的切换&#xff0c;引入了中断机制。 中断是计算机系统中的一种事件&#xff0c;它会打断CPU当前正在执行的程序&#xff0c;转而执行另一个程序或者执行特定的处理程序。中断可以来自外部设备&#xff08;如键盘、鼠标、网络等&#xff09;、软…

1072 Gas Station (最短路径同时求最短路,最长路,总路径)

题意&#xff1a;给定几处居民住所与几处预选加油站点&#xff0c;求离最近的居民住所最远且所有居民都在该站点服务区内的加油站点&#xff0c;如果有多个&#xff0c;则选择平均距离最小的&#xff0c;再有多个&#xff0c;选择序号最小的。 思路&#xff1a;刚开始不知道未…

振南技术干货集:FFT 你知道?那数字相敏检波 DPSD 呢?(1)

注解目录 1 、DPSD 的基础知识 1.1 应用模型 1.2 原理推导 1.3 硬件 PSD &#xff08;相敏检波&#xff0c;就是从繁乱复杂的信号中将我们关心的信号检出来&#xff0c;同时对相位敏感。 数学原理&#xff0c;逃不掉的&#xff0c;硬着头皮看吧。&#xff09; 2 、DPSD …

【电路笔记】-电阻器颜色代码与阻值计算

电阻器颜色代码与阻值计算 文章目录 电阻器颜色代码与阻值计算1、概述2、计算电阻器颜色代码值3、贴片电阻器 电阻器颜色编码使用色带轻松识别电阻器的电阻值及其百分比容差。 1、概述 由于有许多不同类型的电阻器可用&#xff0c;我们需要形成电阻器颜色代码系统以便能够识别…

LuatOS-SOC接口文档(air780E)--repl - “读取-求值-输出” 循环

示例 --[[ 本功能支持的模块及对应的端口 模块/芯片 端口 波特率及其他参数 Air101/Air103 UART0 921600 8 None 1 Air105 UART0 1500000 8 None 1 ESP32C3 UART0 921600 8 None 1 -- 注意, 简约版(无CH343)不支持 ESP32C2 …

Java 注解在 Android 中的使用场景

Java 元注解有 5 种&#xff0c;常用的是 Target 和 Retention 两个。 其中 Retention 表示保留级别&#xff0c;有三种&#xff1a; RetentionPolicy.SOURCE - 标记的注解仅保留在源码级别中&#xff0c;并被编译器忽略RetentionPolicy.CLASS - 标记的注解在编译时由编译器保…

力扣104. 二叉树的最大深度

目录 1.解题思路2.代码实现 1.解题思路 如果我们知道了左子树和右子树的最大深度&#xff0c;那么该二叉树的最大深度即为大的深度加一,而左子树和右子树的最大深度又可以以同样的方式进行计算。因此我们可以用「深度优先搜索」的方法来计算二叉树的最大深度。具体而言&#x…

Vue框架学习笔记——事件scroll和wheel的区别

文章目录 前文提要滚动条滚动事件 scroll鼠标滚动事件 wheel二者不同点 前文提要 本人仅做个人学习记录&#xff0c;如有错误&#xff0c;请多包涵 滚动条滚动事件 scroll scroll事件绑定html页面中的指定滚动条&#xff0c;无论你拖拽滚动条&#xff0c;选中滚动条之后按键盘…