Codeforces Round 954 (Div. 3)
A. X Axis
1.既然要求每个点到a到距离之和最小,不妨让点a为3个点中的中间点,也就是先对三个数从小到大排序,然后输出首尾数减中间值的绝对值之和即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
typedef pair<int,int> pii;
#define all(v) v.begin(),v.end()
void solve()
{
int a[3];
for(int i=0;i<3;i++)
{
cin>>a[i];
}
sort(a,a+3);
cout<<abs(a[0]-a[1])+abs(a[2]-a[1]);
cout<<endl;
}
signed main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
}
B. Matrix Stabilization
1.显然如果一个数比它上下左右四个相邻的数大,它就会转化成这四个数中最大的数
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
#define x first
#define y second
#define all(v) v.begin(),v.end()
int dx[]={0,1,-1,0};
int dy[]={-1,0,0,1};
void solve()
{
int n,m;
cin>>n>>m;
int a[105][105];
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++)
{
int ma=-1;
if(i>0) ma=max(ma,a[i-1][j]);
if(i<n-1) ma=max(ma,a[i+1][j]);
if(j>0) ma=max(ma,a[i][j-1]);
if(j<m-1) ma=max(ma,a[i][j+1]);
//先找了合法的上下左右的最大值
//然后比较这个最大值和当前位置的值,如果这个位置的值大于这个最大值就更新
cout<<min(ma,a[i][j])<<" ";
}
cout<<endl;
}
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
C. Update Queries
1.因为我们可以改变字符串c的下标和索引数组,那么假如说索引数组中,没有重复的数字,也就是s中一个字符只被修改一次,那么将c按字典序排序,索引组也从小到大排序,自然修改后的s就是字典序最小的。
2.当索引数组有重复数字也没关系,因为我们可以把多余的那些次数用字典序大的字符来消耗掉,那么最终也变成了1中的操作步骤,所以答案就是我们先对c排序,然后按照索引从小到大修改即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
typedef pair<int,int> pii;
#define all(v) v.begin(),v.end()
int dx[]={0,1,-1,0};
int dy[]={-1,0,0,1};
void solve()
{
int n,m;
map<int,int>mp;
cin>>n>>m;
string s1;
cin>>s1;
int a[100005];
for(int i=0;i<m;i++)
{
cin>>a[i];
mp[a[i]-1]=1;
}
string s2;
int p=0;
cin>>s2;
sort(all(s2));
// cout<<s1<<" "<<s2;
//cout<<endl;
for(int i=0;i<s1.size();i++)
{
if(mp[i]==1)
{
if(p<s2.size()) s1[i]=s2[p++];
}
}
cout<<s1<<endl;
}
signed main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
}
D. Mathematical Problem
1.因为只放n-2个符号,所以一定有一个数是两位数,并且因为只有+和️。
2.我们可以枚举这个两位数,然后算出每种的结果,比较找最大值即可
3.当我们一种方案里有0的时候,可以全部用乘号让结果为0,即为最小,当一种方案有数字1,我们用乘1让其保持不变,其余的数用加法,结果便为最小
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
#define x first
#define y second
#define all(v) v.begin(),v.end()
int dx[]={0,1,-1,0};
int dy[]={-1,0,0,1};
void solve()
{
int n; cin>>n;
string s; cin>>s;
int ve[n];
for(int i=0;i<n;i++)
{
ve[i]=s[i]-'0';
}
int res=1e9;
//因为只能添加n-2个符号,所以有一个数字肯定是两位数
for(int i=1;i<n;i++)//i从1开始 因为j要==i-1
{
vector<int>num;
for(int j=0;j<n;j++)
{
if(j==i-1){//放这个两位数进去
int x=ve[j]*10+ve[j+1];
num.push_back(x);
j++;//这里把下一位用了 j记得++
}else{//放一位数进去
num.push_back(ve[j]);
}
}
//检查这些数 如果有0 相当于全用乘法可以得到最小值为0
//如果某个数为1,相当于乘1,不改变数的值
//其余的数全部用加法即可以得到值最小
int ans=0;
for(int i=0;i<num.size();i++)
{
if(num[i]==0){
cout<<0<<endl;
return;
}else if(num[i]==1)
{
continue;
}else{
ans+=num[i];
}
}
if(ans==0) ans++; //如果没有输出0,但ans为0,可能是1 01这种情况
res=min(ans,res);
}
cout<<res<<endl;
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
Codeforces Round 954 (Div. 3)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- bootwiki-Elasticsearch教程
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html Elasticsearch教程 Elasticse ...
- mac文件目录结构
详解MAC硬盘中各个文件夹 详解MAC硬盘中各个文件夹 打开Macintosh HD你会发现内中有四个文件夹 分别有--应用程序(Applications).系统(System).用户(User).资 ...
- Java常用框架面试题
SpringSpring如何解决循环依赖循环依赖的产生可能有很多种情况,例如: A的构造方法中依赖了B的实例对象,同时B的构造方法中依赖了A的实例对象A的构造方法中依赖了B的实例对象,同时B的某个fi ...
- dart中Set类型详解
01==> Set 它的主要功能是去除重复的数组内容: Set是没有顺序且不能够重复的数组,所以不能够通过索引值去获取内容 var s = new Set(); s.add('苹果'); s.a ...
- Node.js 与 PostgreSQL 集成:深入 pg 模块的应用与实践
title: Node.js 与 PostgreSQL 集成:深入 pg 模块的应用与实践 date: 2025/2/5 updated: 2025/2/5 author: cmdragon exce ...
- Mac安装Hive
一.基础信息 下载地址:http://archive.apache.org/dist/hive/ 版本:hive3.1.1 依赖:hadoop3.2.1.mysql 解压目录:/Users/rob ...
- DotNet跨平台 - docker+nginx+ssl 负载均衡
环境:CentOS7 服务器需要安装:docker.nginx.OpenSSL 一.部署方案 在linux服务器上,我们的Web站点程序采用docker容器部署,为了演示负载均衡,我们在同一台linu ...
- 牛客题解 | 单组_spj判断YES与NO
题目 题目链接 解题思路 后台有spj代码,能对同学们的输出数据进行校验,符合条件即可通过. 附赠 spj 代码 #include <iostream> #include <fstr ...
- docker - [06] 安装部署Tomcat
题记部分 一.官方测试镜像 官方文档给出以下命令,一般用来测试,用完即删,下载并运行镜像,退出镜像就会自动删除镜像?亲测不会自动删除 docker run -it --rm tomcat:9.0 使用 ...
- 借Processing语言及IDE做DOS批处理的事务( 批量修改文件夹或文件的名字 )
一直想用Processing语言做一些批处理的事务,因为其自带的IDE功能紧凑易用,极度轻量,又加上Java语言的生态极具友好,处理一些windows相关操作完全可行,简单快捷. 这次就是用它做[批量 ...