跳到正文

个人记录

2024.10.12

jiangxiangliang约 5 分钟
原文
文章信息与版本

文章信息

发布
2024年10月13日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 5 分钟

版本

  1. v1当前

T1:

第一题是一道水题,只需要一个for循环,if判断就可以了

C++
#include<bits/stdc++.h>
using namespace std;
long long k,a,b,c;
int main(){
	cin>>k>>a>>b>>c;
	long long sum=0;
	for(long long i=1;i<=k;i++){
		long long x;cin>>x;
		if(x>100){
  		long long tenp=x-100;
  		sum+=10*a+90*b+tenp*c;
  	}else if(x>10){
  		long long tenp=x-10;
  		sum+=10*a+tenp*b;
  	}else{
  		sum+=x*a;
  	}
	}
	cout<<sum;
	return 0;
}

T2:

第二题只需要按照题意先输入原来的海拔,再输入交换的两块海拔坐标,交换一下,最后查看上下左右是否小于a[i][j],一定不能小于等于a[i][j],如果都小于就sum++,不要用数组存起来,会WA

C++
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+7;
int a[maxn][maxn];
int b1[maxn];
int b2[maxn];
int b;
int n,m,T;
int sum;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	cin>>T;
	for(int i=1;i<=T;i++){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		swap(a[x1][y1],a[x2][y2]);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j-1]<a[i][j]&&a[i][j+1]<a[i][j]&&a[i-1][j]<a[i][j]&&a[i+1][j]<a[i][j]){
				sum++;
			}
		}
	}
	cout<<sum<<endl;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j-1]<a[i][j]&&a[i][j+1]<a[i][j]&&a[i-1][j]<a[i][j]&&a[i+1][j]<a[i][j]){
				cout<<i<<' '<<j<<endl;
			}
		}
	}
	
	return 0;
}

T3:

第三题也是一道模拟题,用一个结构体来存储地址,让后边输入要去的地址,如果地址的数都是0,就退出

C++
#include<bits/stdc++.h>
using namespace std;
const int maxn=10e3+7;
struct N{
	int x,y;
}a[maxn][maxn];
int n,m,sx,sy; 
int main(){
	cin>>m>>n>>sx>>sy;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j].x>>a[i][j].y;
		}
	}
	cout<<sx<<" "<<sy<<endl;
	while(1>0){
		int x1=a[sx][sy].x;
		int y1=a[sx][sy].y;
		if(x1==0&&y1==0){
			break;
		}
		cout<<a[sx][sy].x<<" "<<a[sx][sy].y<<endl;
		sx=x1;
		sy=y1;
		
	}
	return 0;
}

T4:

T5:

第五题可以暴力用一个check来搜索以(i,j)为中心的一条直线上最大的回文串,那如何判断回文串呢?我们可以用双指针来作为下标,如果碰到边界就判断是行多还是列多

C++
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000+7;
int a[maxn][maxn];
int n,m;
int check(int x,int y){
	int y1=y,y2=y;
	int sum=0,ans=0;
	while(a[x][y1]==a[x][y2]){
		sum++;
		y1--;y2++;
		if(y1==0||y2==n+1){
			break;
		}
	}
	int x1=x,x2=x;
	while(a[x1][y]==a[x2][y]){
		ans++;
		x1--;x2++;
		if(x1==0||x2==n+1){
			break;
		}
	}
	sum=sum*2-1;
	ans=ans*2-1;
	sum=max(sum,ans);
	return sum;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char s;cin>>s;
			a[i][j]=s-'a';
		}
	}
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		cout<<check(x,y)<<endl;
	}
	return 0;
}

T6

原文