2.2日总结

文章讲述了如何使用动态规划解决最大正方形问题,通过状态转移方程优化计算过程。同时介绍了电子表格中的坐标系统转换,包括R23C55和BC23格式之间的转换算法。
摘要由CSDN通过智能技术生成

动态规划(给定一个问题将其分解为子问题直到子问题能够解决,然后把子问题的结果保存起来以减少重复计算,根据子问题答案反推原答案)解决最大正方形

# 最大正方形

## 题目描述

在一个 $n\times m$ 的只包含 $0$ 和 $1$ 的矩阵里找出一个不包含 $0$ 的最大正方形,输出边长。

## 输入格式

输入文件第一行为两个整数 $n,m(1\leq n,m\leq 100)$,接下来 $n$ 行,每行 $m$ 个数字,用空格隔开,$0$ 或 $1$。

## 输出格式

一个整数,最大正方形的边长。

## 样例 #1

### 样例输入 #1

```
4 4
0 1 1 1
1 1 1 0
0 1 1 0
1 1 0 1
```

### 样例输出 #1

```
2
```

i,j点所能构成的最大正方形(以i,j为正方形的最右端)与其i-1,j和i,j-1和i-1,j-1所能构成的最大正方形息息相关如果如果他们三个都能构成2边长的正方形且i,j此时为1时那么就能构成3边长的最大正方形若j=0否则直接为0边长的正方形就是这个状态转移方程难找

#include<bits/stdc++.h>
using namespace std;
int a[105][105];
int f[105][105];
int main()
{
	int n,m;//定义两个变量 
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);//输入数据 
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]==1)
			{
				f[i][j]=min(min(f[i-1][j],f[i][j-1]),f[i-1][j-1])+1; 
			}
			else
			f[i][j]=0;
		}
	}
	int max=f[1][1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(f[i][j]>max)max=f[i][j];
		}
	}
	cout<<max;
	return 0; 
}

二:

# Spreadsheets

## 题面翻译

人们常用的电子表格软件(比如: Excel)采用如下所述的坐标系统:

第一列被标为 A,第二列为 B,以此类推,第 $26$ 列为 Z。接下来为由两个字母构成的列号: 第 $27$ 列为 AA,第 $28$ 列为 AB $\cdots$ 在标为 ZZ 的列之后则由三个字母构成列号,如此类推。

行号为从 $1$ 开始的整数。

单元格的坐标由列号和行号连接而成。比如,BC23 表示位于第 $55$ 列 $23$ 行的单元格。

有时也会采用被称为 RXCY 的坐标系统,其中 $X$ 与 $Y$ 为整数,坐标 $(X$,$Y)$ 直接描述了对应单元格的位置。比如,R23C55 即为前面所述的单元格。

您的任务是编写一个程序,将所给的单元格坐标转换为另一种坐标系统下面的形式。

## 输入

第一行一个整数 $n$ $(1$ $\le$ $n$ $\le$ $10^5)$ 表示将会输入的坐标的数量。

接下来 $n$ 行,每行一个坐标。

注意: 每个坐标都是正确的。此外不会出现行号或列号大于 $10^6$ 的单元格。

输出 $n$ 行,每行一个被转换的坐标。

## 输出
$n$ 行,每行一个被转换的坐标。

## 题目描述

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

## 输入格式

The first line of the input contains integer number $ n $ ( $ 1<=n<=10^{5} $ ), the number of coordinates in the test. Then there follow $ n $ lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than $ 10^{6} $ .

## 输出格式

Write $ n $ lines, each line should contain a cell coordinates in the other numeration system.

## 样例 #1

### 样例输入 #1

```
2
R23C55
BC23
```

### 样例输出 #1

```
BC23
R23C55
```

这是用的最原始滴方法没有技巧全是感情好吧

#include<bits/stdc++.h>
using namespace std;
char a[100000];
char b[100000];
char c[100000];
char d[100000];
void solve1(char a[],int l)
{int g=0;int sum=0;int f=1;
 
	for(int i=0;i<l;i++)
	{if(a[i]>='A'&&a[i]<='Z')
	   {
	   
		b[g]=a[i];//把字符全部存储起来 
		g++;}
	}
	for(int i=g-1;i>=0;i--)
	{
		sum+=(a[i]-'A'+1)*f;
		f=f*26;
	} 
	cout<<"R";
	for(int i=g;i<l;i++)
	{
		cout<<a[i];
	}
	cout<<"C";
	cout<<sum<<endl;
}
void solve2(char a[],int l)//说明这是R23C55这种 
{int g=0;int f=1;int s=0;
	  for(int i=l-1;;i--)
	  {
	  	if(a[i]>='A'&&a[i]<='Z')
	  	{
	  		break;
		  }
		  else
		  {
		  	g=g+(a[i]-'0')*f;
		  	f=f*10;
		  	s++;
		  }
	   } 
	   int v;int h=0;
	   while(g!=0)//例如将55转化为26进制
	   {v=g%26;
	   	g=g/26;
	   	c[h]=v;
	   	h++;
	   }int q=0;
	   for(int j=h-1;j>=0;j--)
	   {
	   	d[q]=c[j]+'A'-1;
	   	q++;
	   }
	   for(int j=0;j<q;j++)
	   {
	   	cout<<d[j];
	   }
	   for(int j=1;j<l-s-1;j++)
	   {
	   	cout<<a[j];
	   }
	   cout<<endl;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
	
	scanf("%s",a);
	int l=strlen(a);
	int flag1=0,flag2=0; 
	   for(int i=0;i<l;i++)
	   {
	   	 if(a[i]>='0'&&a[i]<='9')//出现了数字 
	   	 {
	   	 	flag1=1;
			}  
			if(a[i]>'9'&&flag1==1)//之后又再次出现了字母 
			{
				flag2=1;
				break;
			}
	   }
	   if(flag2==0)//bc23这种 
	   {
	   	solve1(a,l);
		}
		else
		{
			solve2(a,l);//R23C55这种
		 } 
		 memset(a,0,sizeof(a)); //清空数组
		 memset(b,0,sizeof(b)); 
		 memset(c,0,sizeof(c)); 
		 memset(d,0,sizeof(d)); 
     }
}

  • 23
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值