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
output
题目大意:
简单思维题目,如例子长为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
output
题目大意:
题意很简单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;
}
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;
}
相关文章推荐
- 又一道简单题&&Ladygod(两道思维水题)
- hdoj 1229 还是A+B(简单水题,但是因为思维不够活跃,一开始做的很麻烦)
- 通过细心思考解决看似简单的问题(java求两个int值的平均数)
- HDU 4466 Triangle 第二次积分赛C题(思维+简单dp+细心)
- cf(思维题,判断两个大数的大小的比较方法)
- ZOJ 3657The Little Girl..2012长春现场赛C题(简单思维+细心)
- Riverside Curio(CF Round #472 D div2 思维水题)
- 维护PHP程序时,两个简单的调试用函数
- POJ 2545+2591+2247+1338简单水题
- ZOJ 1205题解本来是一道大数运算水题,可是却纠结了很久,原因是没能真正读懂题意,要求的计算必须是一一对应输出即使前面出现几个0最后也要把前面的0输出,看别人用C++自己还是两个都提交了结果还是C占的内存少。
- 利用js获取服务器时间的两个简单方法
- CF - 782E. Underground Lab - 思维+dfs
- js比较两个日期大小的简单方法
- CF 155C. Hometask 思维+模拟.
- 两个简单的API限流实现方案
- cf 226b 唯美思维题~.cpp
- HDOJ/HDU 1256 画8(绞下思维~水题)
- CF 767C.Garland 思维,树三等分
- 【ZOJ3947 The 13th Zhejiang Provincial Collegiate Programming ContestL】【水题】Very Happy Great BG 简单求和
- 利用js获取服务器时间的两个简单方法