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.hqwc.cn/news/223241.html

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

相关文章

name 属性:提高 Vue 应用可维护性的关键

&#x1f90d; 前端开发工程师&#xff08;主业&#xff09;、技术博主&#xff08;副业&#xff09;、已过CET6 &#x1f368; 阿珊和她的猫_CSDN个人主页 &#x1f560; 牛客高级专题作者、在牛客打造高质量专栏《前端面试必备》 &#x1f35a; 蓝桥云课签约作者、已在蓝桥云…

JavaSE 知识点总结

路在脚下&#xff0c;行则将至 目录 1. 初始Java 1.1 Java之父——高斯林 1.2 一次编译&#xff0c;到处运行 1.3 注释 2. 数据结构与变量 2.1 数据类型 2.2 变量 2.3 常量 3. 运算符 3.1 逻辑与 && 3.2 逻辑 || 3.3 逻辑非 ! 3.4 特殊的位运算符(C语言没有)…

javascript 运算符

javascript 运算符 目录 javascript 运算符 一、算术运算符 1、自增运算符 2、自减运算符 二、比较运算符 三、赋值运算符 四、逻辑运算符 五、条件运算符 疑难解答&#xff1a; 这一节&#xff0c;我们来介绍JavaScript的运算符。运算符是完成一系列操作的符号&…

基于HTML+CSS+JavaScript的登录注册界面设计

一、界面效果: 二、HTML代码: 登录注册html: 登录成功html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <h1>登录成功!</h1> </body> <…

线程基本方法

1。设置线程名 继承Thread类的线程&#xff0c;可以直接使用.setName()方法&#xff0c;设置线程名。也可以使用构造方法&#xff0c;需要注意java默认不继承构造方法&#xff0c;所以需要自己调用下父类的构造方法。 public class Demo {public static void main(String[…

powershell获取微软o365 21v日志

0x00 背景 o365 21v为o365的大陆版本&#xff0c;主要给国内用户使用。微软提供了powershell工具和接口获取云上日志。微软o365国内的代理目前是世纪互联。本文介绍如何用powershell和配置证书拉取云上日志。 0x01 实践 第一步&#xff0c;ip权限开通&#xff1a; 由世纪互联…

CGAN原理讲解与源码

1.CGAN原理 生成器&#xff0c;输入的是c和z&#xff0c;z是随机噪声&#xff0c;c是条件&#xff0c;对应MNIST数据集&#xff0c;要求规定生成数字是几。 输出是生成的虚假图片。 判别器的输入是 1.生成器输出的虚假图片x; 2.对应图片的标签c 来自真实数据集&#xff0c;且…

什么是高性能计算岗位

最近有小伙伴咨询什么是高性能计算岗位。 1、什么是高性能计算 高性能计算&#xff0c;在很多招聘信息中也会被标注为 HPC&#xff0c;是 High Performance Computing 的缩写。 目前很多 AI 公司或者从事 AI 的部门招聘都有这个岗位需求&#xff0c;我从某聘上截取了几个有代…

Shopee买家号想要多开怎么解决?

拥有多个Shopee买家号有很多优势。多账号可以帮助卖家获得更多流量、还能帮助提供关键词排名、提高销量等。 但是要管理多个Shopee买家号并非易事。面对不同账号的登录、注销和切换&#xff0c;可能会花费大量的时间和精力。而且&#xff0c;Shopee平台对于使用同一IP地址同时登…

Android Termux SFTP如何实现远程文件传输

文章目录 1. 安装openSSH2. 安装cpolar3. 远程SFTP连接配置4. 远程SFTP访问4. 配置固定远程连接地址 SFTP&#xff08;SSH File Transfer Protocol&#xff09;是一种基于SSH&#xff08;Secure Shell&#xff09;安全协议的文件传输协议。与FTP协议相比&#xff0c;SFTP使用了…

微信api开发接口文档

简要描述&#xff1a; 搜索联系人 请求URL&#xff1a; http://域名地址/searchUser 请求方式&#xff1a; POST 请求头Headers&#xff1a; Content-Type&#xff1a;application/jsonAuthorization&#xff1a;login接口返回 参数&#xff1a; 参数名必选类型说明wI…

通俗易懂的spring Cloud;业务场景介绍 二、Spring Cloud核心组件:Eureka 、Feign、Ribbon、Hystrix、zuul

文章目录 通俗易懂的spring Cloud一、业务场景介绍二、Spring Cloud核心组件&#xff1a;Eureka三、Spring Cloud核心组件&#xff1a;Feign四、Spring Cloud核心组件&#xff1a;Ribbon五、Spring Cloud核心组件&#xff1a;Hystrix六、Spring Cloud核心组件&#xff1a;Zuul七…