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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. Golang-文件处理11

    http://c.biancheng.net/golang/102/ Go语言自定义数据文件 对一个程序非常普遍的需求包括维护内部数据结构,为数据交换提供导入导出功能,也支持使用外部工具来处理数据.由 ...

  2. tar基本命令

    常用基本命令 压缩文件 # touch a.txt # tar -czvf test.tar.gz a.txt  //或  tar -czvf /path/to/file.tar.gz file 列出 ...

  3. 镜像分层复用与Dockerfile

  4. 解决线程安全问题的方式三:Lock锁 --- JDK5.0新增

    Lock( 锁) 从JDK 5.0开始,Java提供了更强大的线程同步机制--通过显式定义同步锁对象来实现同步.同步锁使用Lock对象充当. java.util.concurrent.locks. ...

  5. 并发编程 - 线程同步(三)之原子操作Interlocked简介

    上一章我们了解了3种处理多线程中共享资源安全的方法,今天我们将更近一步,学习一种针对简单线程同步场景的解决方案--Interlocked. 在此之前我们先学习一个概念--原子操作. 01.原子操作 原 ...

  6. 2025苹果春季发布会前瞻:新品迭出,Apple Intelligence国行版即将上线!

    随着2025年的到来,苹果公司的春季发布会也渐行渐近.作为科技行业的领军企业,苹果每一次的新品发布都备受瞩目.本次春季发布会,苹果预计会带来一系列令人期待的新品,同时,国行Mac用户也将迎来一个重大更 ...

  7. 1.6~THUWC 的总结

    THUWC 虽然拿到了一等奖,但是其实不如预期的发挥. Day1 获得 260~300 分.快速地想出了 T1T2 然后在调试上花费了很多的时间,T3 没有想出来,T4 想出了 \(O(n\log^3 ...

  8. npcap实战抓包教程

    npcap 是一个用于 Windows 系统的网络抓包库,基于 WinPcap 的改进版本,支持最新的 Windows 特性和协议(如 IPv6).它通常与 Wireshark 或 Nmap 等工具一 ...

  9. go实现设计模式(1)——简介

    六大原则 开闭原则(Open Close Principle) 对扩展开放,对修改关闭.对程序进行拓展时,尽量不去修改原有的代码,应该通过扩展实体的行为来实现. 里氏替换原则(Liskov Subst ...

  10. linux rpm包下载

    下载地址 pkg.org 下载方法 搜索包名 找到需要的包 点击去,找到Download wget [Download url] 没有包管理器,恶心,真他妈恶心,我都不想使,还说啥稳定,环境都配不起来 ...