CodeForces解题报告——1
来源:互联网 发布:软件测试招聘上海 编辑:程序博客网 时间:2024/05/30 02:52
Codeforces解题报告
——序号1
题目1A: Theatre Square
题意:
在一个n*m的矩形块里面用,a*a 的正方形瓷砖铺满它,问最少个数?
只需要计算边界上,最多需要的数量,然后相乘就好!
代码:
int main(){#ifdef LOCAL //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);#endif // LOCAL LL n, m ,a; while(cin >> n >> m >> a) { LL width = n / a + ((n % a == 0) ? 0 : 1); LL height = m / a + ((m % a == 0) ? 0 : 1); cout << width * height << endl; } return 0;}
题目1B:Spreadsheets
题意:
在两种坐标中进行转换,一种是R*C*类型,一种是Excel表格的形式
已知在RXCY和AA11这两个坐标形式中,R型坐标Y是不用转换的直接就是Excel表格中的行数。
把一个数字转换为大写字母的基本方式是:
反复让sum和26求余数,如果余数不为0,则对应的字母为'A' - 1 + 余数,否则直接等于’Z'
然后sum = sum / 26; 但是如果余数为零,sum除以26以后,还需要减一 这是关键!!!
最后将所得字符反向输出即可!
比如28 -> 28 % 26 = 2 --> B
28 / 26 = 1
1 % 26 = 1 --> A
输出结果为AB
把大写字母转换为数字的方法为:
参考二进制转换十进制 x1 * 2 ^ k + ...... + xn * 2 ^ 0;
即x * 26 ^ k + .......
其中x为字母的下表,A为1,k表示字母所在的位置,从0计数
比如 AB 就是 1*26^1 + 2 = 28
代码:
const int maxn = 100;char cmd[maxn];int Pow[] = { 1, 26, 676, 17576, 456976, 11881376 };int pow2[] = { 1, 10, 100, 1000, 10000, 100000, 1000000 };void fun1(){int k = 0;int sum = 0;int pos = 0;int len = strlen(cmd);for (int i = len - 1; i >= 0; --i)if (isdigit(cmd[i]))sum += (cmd[i] - '0') * pow2[k++];elsebreak;char tmp[maxn];int s = 0; while (sum){if (sum % 26 == 0){tmp[s++] = 'Z';sum = sum / 26 - 1;}else{tmp[s++] = 'A' - 1 + sum % 26;sum /= 26;}}for (int i = s - 1; i >= 0; --i)printf("%c", tmp[i]);for (int i = 1; i < len; ++i)if (isdigit(cmd[i]))printf("%c", cmd[i]);elsebreak;printf("\n");}void fun2(){int len = strlen(cmd);int sum = 0;int pos = 0;printf("R");for (int i = 0; i < len; ++i)if (isdigit(cmd[i]))printf("%c", cmd[i]);printf("C");int k = 0;for (int i = len - 1; i >= 0; --i)if (isalpha(cmd[i]))sum += (cmd[i] - 'A' + 1) * Pow[k++];printf("%d\n", sum);}int main(){#ifdef LOCAL// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // LOCALint n;scanf("%d", &n);while (n--){scanf("%s", cmd);int len = strlen(cmd);bool flag = false;for (int i = 1; i < len; ++i)if (cmd[i] == 'C')flag = true;if (len >= 4 && cmd[0] == 'R' && isdigit(cmd[1]) && flag)fun1();elsefun2();}return 0;}
题目1C:Ancient Berland Circus
题意:
代码:
0 0
- CodeForces解题报告——1
- CodeForces解题报告——4
- codeforces 1A 解题报告
- codeforces 1B 解题报告
- Codeforces Round #250 (Div.1) 解题报告
- CUGBACM Codeforces Tranning 1 解题报告
- CUGBACM Codeforces Tranning 1 解题报告
- CUGBACM Codeforces Tranning 1 解题报告
- Codeforces Round #327 (Div. 1) 解题报告
- Codeforces Round #326 (Div. 1) 解题报告
- Codeforces Round #325 (Div. 1) 解题报告
- CodeForces#round308C解题报告
- 解题报告:CodeForces
- 迷宫—解题报告
- CodeForces Round#35解题报告
- Codeforces 117C解题报告
- codeforces #133 div2 解题报告
- codeforces #134 div2 解题报告
- 实例讲解网站前台界面开发流程
- c语言_结构体对齐
- tkinter Combobox组件
- 集成tomcat插件到eclipse
- js 字符转义
- CodeForces解题报告——1
- Objective-C 程序设计 第七章
- 八大排序算法
- WPF导学目录
- 动态规划算法
- 浅谈企业应用软件架构设计过程
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- LeetCode OJ 之 Nim Game(翻摊游戏)
- Dijkstra算法(单源最短路径)