做了好久 感觉做的有点蠢 题目总体难度不高吧应该 因为考虑的不周WA了两次
题目传送门:http://codeforces.com/contest/1
A. Theatre Square
time limit per test
1 second
memory limit per test
256 megabytes
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.
题解:铺地砖嘛就是 用边长a的正方形铺满一个n*m的平面 不能裁割 然后就直接ceil(n/a)*ceil(m/a) 注意下数据范围可能会超出int。。
AC代码:
#include <cstdio>
#include <cmath>
typedef long long LL;
int main(){
LL n, m, a;
scanf("%I64d%I64d%I64d", &n, &m, &a);
printf("%I64d\n", LL(ceil(1.0*n/a) * ceil(1.0*m/a)));
return 0;
}
B. Spreadsheets
time limit per test
10 seconds
memory limit per test
64 megabytes
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.
题解:两种形式的字符转换 一种是R数字C数字 R行C列 一种是字母数字 字母代表列数字代表行
简单字符串处理 注意点的话一是判断是哪一种格式 因为R23很容易就判断成R23C55的格式了 二是转换的时候关于Z的问题
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 101000;
char col[maxn];
string str;
bool flag;
int len;
int n;
int main() {
int t;
cin >> t;
while(t--) {
cin >> str;
len = str.size();
memset(col, '\0', sizeof(col));
flag = false;
if(str[0] == 'R' && (str[1] >= '0' && str[1] <= '9')) { //判断是哪一种格式的字符串
for(int i = 2; i < len; ++i) {
if(str[i] == 'C') {
flag = true;
break;
}
}
}
if(flag) { //R23C55格式
int r = 0, c = 0;
bool mark = true;
for(int i = 1; i < len; ++i) {
if(str[i] == 'C') {
mark = false;
continue;
}
if(mark) {
r = r * 10 + (str[i] - '0');
}
else {
c = c * 10 + (str[i] - '0');
}
}
for(int i = 0; ; ++i) {
if(c == 0) {
break;
}
int m = c % 26; //对Z做一个特殊处理
if(m == 0) {
m = 26;
c = c / 26 - 1;
}
else {
c /= 26;
}
col[i] = m - 1 + 'A';
}
n = strlen(col);
for(int i = n-1; i >= 0; --i) {
cout << col[i];
}
cout << r << endl;
}
else { //BC55格式
bool mark = true;
int r = 0, c = 0;
for(int i = 0; i < len; ++i) {
if(str[i] >= '0' && str[i] <= '9') {
mark = false;
}
if(mark) {
col[i] = str[i];
}
else {
r = r * 10 + (str[i] - '0');
}
}
n = strlen(col);
for(int i = 0; i < n; ++i) {
c = c * 26 + (col[i] - 'A' + 1);
}
cout << 'R' << r << 'C' << c << endl;
}
}
return 0;
}
C. Ancient Berland Circus
time limit per test
2 seconds
memory limit per test
64 megabytes
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different.
In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges.
Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time.
You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have.
Input
The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point.
Output
Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100.
Examples
input
0.000000 0.000000
1.000000 1.000000
0.000000 1.000000
题解:有一个圆形的斗兽场 圆上有X个木柱 刚好能构成一个正多边形 但是有三个木柱不见了
现在给三个木柱的坐标 判断这个舞台的最小面积 数组合法 绝对能组成三角形 不会大于100边型
海伦公式求出外接圆半径
R= a * b * c / (4 * S)
S= sqrt(p * (p - a) * (p - b) * (p - c))
p = (a + b + c) / 2
余弦定理求三个角
angle = acos(1 - edge * edge / (2 * R * R))
fgcd求三个角最大公约数 就是正多边形分解的n个小三角形两条半径的边夹角
因为是正多边形 所以只要求出一条边与两个半径围成的面积*N就是多边形的面积
最后正弦定理求面积
S = R * R * sin(angle) / 2 * (2 * pi / angle)
AC代码:
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0); //PI
double diameter(double a, double b, double c); //海伦公式
double fgcd(double a, double b); //最大公约数
int main() {
double x[3], y[3];
double edge[3];
for(int i = 0; i < 3; ++i) {
scanf("%lf%lf", &x[i], &y[i]);
}
for(int i = 0; i < 3; ++i) { //求三条边长
edge[i] = sqrt((x[i] - x[(i+1) % 3]) * (x[i] - x[(i+1) % 3]) + (y[i] - y[(i+1) % 3]) * (y[i] - y[(i+1) % 3]));
}
double r = diameter(edge[0], edge[1], edge[2]); //海伦公式求半径
double angle[3];
for(int i = 0; i < 2; ++i) { //三个圆心角
angle[i] = acos(1 - edge[i] * edge[i] / (2 * r * r));
}
angle[2] = 2 * pi - angle[0] - angle[1];
double angle_fgcd = fgcd(angle[0], fgcd(angle[1], angle[2])); //三个圆心角的最大公约数
double s = pi / angle_fgcd * r * r * sin(angle_fgcd); //求面积
printf("%.6f\n", s);
return 0;
}
double diameter(double a, double b, double c) {
double p = (a + b + c) / 2;
double s = sqrt(p * (p - a) * (p - b) * (p - c));
return a * b * c / (4 * s);
}
double fgcd(double a, double b){
if(fabs(a - 0) < 1e-2) {
return b;
}
if(fabs(b - 0) < 1e-2) {
return a;
}
return fgcd(b, fmod(a, b));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)