首页 > 其他分享 >模拟赛

模拟赛

时间:2022-11-12 11:31:18浏览次数:38  
标签:return cout int cin solve tie 模拟



A

模拟赛_#define



大意:给你一串任意的序列,可以通过任意改变他们的位置,问最后能否严格单调递增。

思路:sort一遍,检查是否有相等的项



AC代码:

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;



void solve(){
int n;
cin >> n;

vector<int> a(n + 1);
for(int i = 1; i <= n; i ++) cin>> a[i];

sort(a.begin() + 1 ,a.end());

for(int i = 1; i < n; i++){
if(a[i] == a[i + 1]){
cout << "no\n";
return;
}
}

cout << "yes\n";
}

int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

int t;
cin >> t;
while(t--) solve();


return 0;
}





B

模拟赛_c代码_02


题目大意:

原字符串a

变化后的字符串b

叫你 找回原来的字符串a

变化的要求:将a串  两两拉开,得到b串


ac代码:

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;


void solve(){
string b;
cin >> b;


string a;
for(int i = 0 ; i < b.size(); i ++){ //遍历b串,求a串
if(i == 0 || i == b.size() - 1) {
a += b[i];
}else{
a += b[i];
i++;
}
}

cout << a << endl;
}

int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

int t;
cin >> t;
while( t--) solve();


return 0;
}






C

模拟赛_ios_03

大意:

给你一串数字序列a

询问是否可以变成字符串序列

变换规则:相同的数字,必须变成相同的字母。变成哪个字母是任意。

思路:检查所有相等的数字,对应变成的字母必须相等。否则就是no


AC代码:

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;


void solve(){
int n;
cin >> n;//输入n

vector<int> a(n + 1);
for(int i = 0; i < n ;i ++) cin >> a[i]; //读取第一行数字序列



string b; //读取string
cin >> b;


for(int i = 0; i < n; i ++ ){
for(int j = i; j < n; j ++){
if(a[i] == a[j] && b[i] != b[j]) { //当前数字和后面的数字相等,必须变成同一个字母
cout << "no\n";
return;
}
}
}

cout << "yes\n";


}

int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t;
cin >> t;
while(t--) solve();


return 0;
}





D




模拟赛_ios_04



题目大意:

求2个下标和最大。 要求这两个下标对应的值必须互质。

思路:去掉重复元素,拿到最大下标。O方暴力找质数,维护一个最大下标和ans


AC代码:

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

bool tag[1000 + 5];
int sp_max[1000 + 5];

int gcd(int a, int b){
if(b) return gcd(b, a % b);
return a;
}

void solve(){
int n;
cin >> n;

memset(tag, 0, sizeof tag);
memset(sp_max, 0, sizeof sp_max);

vector<int> a(n + 1);
for(int i = 1;i <= n; i ++) cin >> a[i];//输入数据


//去掉重复元素,保留下标最大值
for(int i = 1; i <= n ;i ++){
tag[a[i]] = true;
sp_max[a[i]] = i;
}

vector<int> b; //将出现过的值,添加到数组里
for(int i = 1; i <= 1000; i ++){
if(tag[i]) b.push_back(i);
}

int ans = -1;
// 暴力搜索,这1000个数据
for(int i = b.size() - 1; i >= 0; i --){
for(int j = b.size() - 1; j >= 0; j --){
//判断,i j 对应的元素,互质
if(gcd(b[i], b[j]) == 1) {
//互质
ans = max(ans, sp_max[b[i]] + sp_max[b[j]] );
}
}
}
cout << ans << endl;


}

int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
int t;
cin >> t ;
while(t--) solve();


return 0;
}






E

模拟赛_#define_05


题目大意:

给一个x序列,代表餐厅的价格

给一个y序列,代表这些人兜里有多少钱

询问,这些人两两组队或者多人组队,最多可以去这些餐馆多少天?


思路:用yi-xi排序, 左边得到的是穷人,数组右边的是富人。富人能带一个穷人就算赢一天。


AC代码:


#include <bits/stdc++.h>

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define endl '\n'
#define x first
#define y second
using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
//函数内初始化数组={}

struct node{
int x, y, substract;
}a[100005];

bool cmp(struct node &a, struct node &b){
return a.substract < b.substract;
}

void solve(){
int n;
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i].x;
for(int j = 1; j <= n; j ++) cin >> a[j].y;
for(int i = 1; i <= n; i ++) a[i].substract = a[i].y - a[i].x;//输入数据,求出yi - xi的差值


sort(a + 1, a + 1 + n, cmp);


//双指针扫描
int ans = 0;
for(int i = 1, j = n; i < j; i ++){
if(a[i].y + a[j].y >= a[i].x + a[j].x) {
ans ++;
j --;
}
}


cout << ans << endl;


}

int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

int t;
cin >> t;
while(t--) solve();


return 0;
}


标签:return,cout,int,cin,solve,tie,模拟
From: https://blog.51cto.com/u_15389271/5846590

相关文章

  • Android实战简易教程-第五十六枪(模拟美团客户端进度提示框)
    用过美团客户端的朋友都知道,美团的加载等待提示很有意思,是一种动画的形式展现给我们,下面我们就对这背后的原理进行了解,然后实现自己的等待动画效果。首先我们准备两张图片:这......
  • 7、模拟验证码
    publicclassPhoneCode{publicstaticvoidmain(String[]args){//模拟验证码发送verifyCode("12345678901");//getRedisCode("123456789......
  • Promise 的模拟实现
    1.为什么会有Promise当我们多次进行有依赖的网络请求或者文件请求时,很可能会造成代码的层层嵌套,导致回调地狱的出现:$.ajax({url:"xxx",success:function(......
  • 广州华锐互动:vr模拟电力场景安全应急培训,为电力行业保驾护航
    近年来,电力行业得到快速发展,这对于电力安全管理提出了更高的要求,只有把电力安全管理工作做好,才能促进电力行业的健康发展。目前电力生产安全事故并不少见,这也反映了电力行......
  • [ Linux ] 缓冲区的理解 以及简易模拟实现封装C标准库
    在输出重定向的时候为什么必须fflush(stdout)才能将内容刷新到指定文件呢?我们当时回答是因为存在缓冲区。那么本篇文章我们将重点了解认识一下缓冲区。0.什么是缓冲区?缓冲区......
  • 算法模拟测试网站
    超好用的算法模拟网站https://alchemist-al.com/各种算法手动步骤模拟 ......
  • 模拟与高精度题解
    此题目特征为储存数字超过longlong类型,c++无法用一个变量存储全部数字解法为开数组来储存各个位上的数字1.字符高精度直接以两种方式处理字符即可#include<bits/std......
  • Android基于坐标对View进行模拟点击事件
    在Android中,我们对于View进行模拟点击事件,很容易,比如调用​​View.performClick​​即可。但是有些时候,我们想要更加精细的点击,比如View的某一区域或者某一点进行点击。比如......
  • 记一次HTTPClient模拟登录获取Cookie的开发历程
    记一次HTTPClient模拟登录获取Cookie的开发历程环境:​ springboot:2.7​ jdk: 1.8​ httpClient:4.5.13设计方案​ 通过新建一个空的cookie库创建出一个Http客户......
  • 计算机等级考试二级C语言模拟试卷(八)
    一、选择题(每小题1分,共40分)(1)下列链表种,其逻辑结构属于非线性结构的是 A)循环链表      B)双向链表        C)二叉链表         D)带链的栈(2)设循......