All the buildings in the east district of Byteburg were built in accordance with the old arbitecture:
they stand next to each other with no spacing inbetween.
Together they form a very long chain of buildings of diverse height, extending from east to west.
The mayor of Byteburg, Byteasar, has decided to have the north face of the chain covered with posters.
Byteasar ponders over the minimum number of posters sufficient to cover the whole north face.
The posters have rectangular shape with vertical and horizontal sides.
They cannot overlap, but may touch each other, i.e. have common points on the sides.
Every poster has to entirely adjoin the walls of certain buildings and the whole surface of the north face has to be covered.
Task Write a programme that:
reads the description of buildings from the standard input, determines the minimum number of posters needed to entirely cover their north faces, writes out the outcome to the standard output.
Byteburg市东边的建筑都是以旧结构形式建造的:建筑互相紧挨着,之间没有空间.它们共同形成了一条长长的,从东向西延伸的建筑物链(建筑物的高度不一).Byteburg市的市长Byteasar,决定将这个建筑物链的一侧用海报覆盖住.并且想用最少的海报数量,海报是矩形的.海报与海报之间不能重叠,但是可以相互挨着(即它们具有公共边),每一个海报都必须贴近墙并且建筑物链的整个一侧必须被覆盖(意思是:海报需要将一侧全部覆盖,并且不能超出建筑物链)
The first line of the standard input contains one integer n (1≤n≤250 000), denoting the number of buildings the chain comprises of.
Each of the following n lines contains two integers di and wi (1≤di,wi≤1 000 000 000), separated by a single space, denoting respectively the length and height of the ��ℎith building in the row.
第一行为一个整数n(1≤n≤250000),表示有n个建筑,接下来n行中,第i行表示第i个建筑物的宽di与高wi(1≤di,wi≤1 000 000 000),中间由一个空格隔开
The first and only line of the standard output should contain one integer, the minimum number of rectangular posters that suffice to cover the north faces of the buildings.
第一个为一个整数,表示最少需要几张海报.
输入 #1复制
5 1 2 1 3 2 2 2 5 1 4
输出 #1复制
4
题目简述:N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们.
感谢@__乱世魇华 提供翻译
1,根据题中所给的条件,我们需要注意当建筑链如果都等高的话,那么只需要一块海报,但如果后面的建筑物都不与前一建筑等高的话,则有几栋建筑我们就需要几个海报,由于此题其实有覆盖,符合先进后出原则,所以我们选用单调栈(此题与所给宽度无关)
(2,如果接下来的建筑高度小于栈顶的建筑高度,则弹出栈,直到遇到比他更小的为止,因为建筑高度小的可以被建筑高度高的覆盖的,如果栈顶不等于即将入栈的建筑高度时,海报必定会增加一个
3,注意题中的覆盖可以是这样的(红色包裹的矩形代表覆盖的海报意味着一块海报
#include
using namespace std;
#define N 250010
int n,d,w,a[N],b[N],top,sum;//注意数据范围
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&d,&a[i]);
}
for(int i=1;i<=n;i++)
{
while(top>0&&a[i]
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<=�<=1051<=n<=105 ), 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 106106 .
Write �n lines, each line should contain a cell coordinates in the other numeration system.
人们常用的电子表格软件(比如: Excel)采用如下所述的坐标系统:
第一列被标为 A,第二列为 B,以此类推,第 2626 列为 Z。接下来为由两个字母构成的列号: 第 2727 列为 AA,第 2828 列为 AB ⋯⋯ 在标为 ZZ 的列之后则由三个字母构成列号,如此类推。
行号为从 11 开始的整数。
单元格的坐标由列号和行号连接而成。比如,BC23 表示位于第 5555 列 2323 行的单元格。
有时也会采用被称为 RXCY 的坐标系统,其中 �X 与 �Y 为整数,坐标 (�(X,�)Y) 直接描述了对应单元格的位置。比如,R23C55 即为前面所述的单元格。
您的任务是编写一个程序,将所给的单元格坐标转换为另一种坐标系统下面的形式。
第一行一个整数 n (1(1 ≤ n ≤105)105) 表示将会输入的坐标的数量。
接下来 n 行,每行一个坐标。
注意: 每个坐标都是正确的。此外不会出现行号或列号大于 106106 的单元格。
输出 n 行,每行一个被转换的坐标。
n 行,每行一个被转换的坐标。
输入 #1复制
2 R23C55 BC23
输出 #1复制
BC23 R23C55t
1.根据题意得出该题得先判断输入时的excel格式,再分别对这俩种格式进行互相转化,由此转换成一个26进制转换的问题
2,26进制1表示'A',2表示‘B’,26会表示的是‘Z’,所以当数字是%26=0时进行特别判断使它变为‘Z’,对于格式的判断我们由输入输出示例得到RC格式中字母前还有可能是数字,但在另一种格式来说的话这是不可能的情况,所以我们根据这个来进行格式判断
3,我们先用一个字符数组来存放ABCDEFG……这26个大写字符,因为1代表的是A,所以0下标的位置我们选择用字符‘0’来进行占位操作
#include
using namespace std;
char s[101];
char c[27]= {'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
void solution2()//列行转rc
{
int sum1=0,sum2=0,i=0;
for(; isupper(s[i]); i++)
(sum2*=26)+=s[i]-'A'+1;//字母转数字并赋给sum2
for(; s[i]; i++)
(sum1*=10)+=s[i]-'0';
printf("R%dC%d\n",sum1,sum2);
}
void solution1()//rc转列行
{
int t[101];
int num1=0,num2=0;
int j=0,i;
for(i=1;isdigit(s[i]); i++)
(num2*=10)+=s[i]-'0';//数字直接转并赋值给另一用来输出的变量
for(++i; s[i]; i++)
{
(num1*=10)+=s[i]-'0';
}
for(; num1; num1=num1/26-!(num1%26))//后面的-!(num1%26)是对Z的特判,每模一次,num1的值也要变,如果num1不为0证明还有下一层
{
if(num1%26)
t[++j]=num1%26;//转换先从后面的字母转
else t[++j]=26;//特别判断
}
for(; j; j--)//因为转换时是先转后面的字母逆序输出
{
putchar(c[t[j]]);
}
printf("%d\n",num2);
}
int main()
{
int n;
int flog;
scanf("%d",&n);
for(int k=1; k<=n; k++)
{
scanf("%s",s);
flog=0;
for(int i=0; s[i]&&!flog; i++)//判断是rc还是列行
{
if(i&&isdigit(s[i-1])&&isupper(s[i]))flog=1;
}
if(flog)solution1();
else solution2();
}
}
如以上有错误之处,还请大佬指正