您的位置:首页 > 其它

CF 1A1B 两个水题(简单思维+细心)

2013-07-25 15:52 393 查看
A. Theatre Square

time limit per test
2 seconds

memory limit per test
64 megabytes

input
standard input

output
standard output

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

Input

The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

Output

Write the needed number of flagstones.

Sample test(s)

input
6 6 4


output
4


       题目大意:

                   简单思维题目,如例子长为6,宽为6的卡片,用4*4的卡片覆盖,最少用几张卡片可以覆盖完。

    题目地址:Codeforces 1A

   

AC代码:

#include<cstdio>
#include<iostream>
using namespace std;

int main()
{
__int64 m,n,t,res,len1,len2;
while(~scanf("%I64d%I64d%I64d",&m,&n,&t))
{
len1=m/t;
if(m%t) len1++;
len2=n/t;
if(n%t) len2++;
res=len1*len2;
printf("%I64d\n",res);
}
return 0;
}


B. Spreadsheets

time limit per test
10 seconds

memory limit per test
64 megabytes

input
standard input

output
standard output

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.

Input

The first line of the input contains integer number n (1 ≤ 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 106 .

Output

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

Sample test(s)

input
2
R23C55
BC23


output
BC23
R23C55


    题目大意:

                  题意很简单R23C55是第23行第55列,BC就是55的意思。从A~Z,AA~ZZ,AAA~ZZZ。

                  主要就是数字转换成字母的时候需要考虑Z,Z比较特殊。

    题目地址:Codeforces 1B

AC代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

char a[18];
int main()
{
int n,i;
cin>>n;
while(n--)
{
cin>>a;
int len=strlen(a);
int flag=0;
int cnt=0;
for(i=1;i<len;i++)
{
if((a[i]>='0'&&a[i]<='9')&&(a[i-1]>='A'&&a[i-1]<='Z'))
cnt++;
}
if(cnt==1) //判断是哪种情况
flag=1;
if(flag) //输入BC23类似的
{
int t1=0,t2=0;
for(i=0;i<len;i++)
{
if(a[i]>='A'&&a[i]<='Z')
t1=t1*26+(a[i]-'A'+1);
else
t2=t2*10+(a[i]-'0');
}
cout<<"R"<<t2<<"C"<<t1<<endl;
}
else
{ //输入R23C55类似的
int t1=0,t2=0;
for(i=1;i<len;i++)
{
if(a[i]>='0'&&a[i]<='9')
t1=t1*10+(a[i]-'0');
else
break;
}
for(int j=i+1;j<len;j++)
{
if(a[j]>='0'&&a[j]<='9')
t2=t2*10+(a[j]-'0');
}

char rs[12],res[12];
int xx=-1;
while(t2)
{
int num=t2%26;
if(num==0)
{
rs[++xx]='Z'; //这里需要分类,为Z的时候特殊
t2--;
}
else
rs[++xx]=num-1+'A';
t2/=26;
}
for(i=0;i<=xx;i++)
res[i]=rs[xx-i];
res[++xx]='\0';
cout<<res<<t1<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: