做了好久 感觉做的有点蠢 题目总体难度不高吧应该 因为考虑的不周WA了两次
题目传送门:http://codeforces.com/contest/1
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.
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
Write the needed number of flagstones.
6 6 4
4
题解:铺地砖嘛就是 用边长a的正方形铺满一个n*m的平面 不能裁割 然后就直接ceil(n/a)*ceil(m/a) 注意下数据范围可能会超出int。。
AC代码:
#include
#include
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;
}
简单字符串处理 注意点的话一是判断是哪一种格式 因为R23很容易就判断成R23C55的格式了 二是转换的时候关于Z的问题
AC代码:
#include
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;
}
现在给三个木柱的坐标 判断这个舞台的最小面积 数组合法 绝对能组成三角形 不会大于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
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));
}