[Codeforces] 1

1A_Theatre Square
atre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.

What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

问题描述:有一个n*m平面,用a*a的小空间将其铺满,允许铺满的平面超过n*m;

代码:

//1A_Theatre Square
#include<iostream>
using namespace std;
int main(){
    int m, n,a;
    cin>>m>>n>> a;
    int i=0,j=0;
    while(i*a<m){
        i++;
    }
    while(j*a<n){
        j++;
    }
    cout<<i*j<<endl;
    return 0;
} 

1B_Spreadsheets

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.

题目描述:给出两种行列位置的表示方法,一个是Excel表示法,一个是(R,C)坐标表示。给出一种表示,输出另外一种表示,两种坐标相互转化;

代码:

#include<cstdio>
#include<cstring>
char s[110000];
char word[30];
void slove1()
{
 
    int len = strlen(s);
    int num1 = 0 ,num2 = 0;
 
    int i = 1;
    while(s[i] >= '0' && s[i] <= '9')
    {
        num2 = num2*10 + s[i] - '0';
        i++;
    }
 
    for(i++;i < len; i++)
        num1 = num1*10+ s[i]-'0';
 
    int temp[10000], cnt = 0;;
    while(num1)
    {
        if(num1 % 26 == 0) {temp[cnt++] = 26; num1 = num1 / 26 - 1;}
        else{
            temp[cnt++] = num1 % 26;
            num1 = num1 / 26;
        }
 
    }
    for(int i = cnt-1; i >= 0; i--)
        printf("%c", word[temp[i]]);
 
    printf("%d\n", num2);
 
}
 
void slove2()
{
    int len = strlen(s);
    int num1 = 0, num2 = 0;
 
    int i = 0;
    while(s[i] >= 'A' && s[i] <= 'Z')
    {
        num1 = num1 * 26 + s[i] - 'A'+1;
        i++;
    }
    for(;i< len; i++)
    {
        num2 = num2 * 10 + s[i] - '0';
    }
    printf("R%dC%d\n", num2, num1);
}
int main ()
{
    word[1] = 'A';
    for(int i = 2; i <= 26; i++)
        word[i] = word[i-1]+1;
 
    int T;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%s", s);
        int len = strlen(s);
 
        int flag = 0;
        for(int i = 0; i < len; i++)
        {
            if(s[i] >= '0' && s[i] <= '9' && s[i+1]>='A' && s[i+1] <= 'Z')
                flag = 1;
        }
 
       if(flag == 1){
            slove1();
       }
       else{
            slove2();
       }
 
    }
    return 0;
}

 

 
posted @ 2020-09-24 23:36  兀凯奇  阅读(208)  评论(0)    收藏  举报