标签:
这道题是Codeforces的第一道题目 感觉比较水 注意点就是int的话 可能会超范围所以用longlong就好啦
题意:大概就是铺地砖 给矩形地面的长和宽还有正方形地砖的边长 求需要多少地砖 地砖不能割开 可以超出范围 分别用矩形地面的长和宽除以地砖的边长 如果不是整除记得结果+1 最后乘在一起就好了 代码很短 第一题确实很水。。。
#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;
}
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.
Output
Write n lines, each line should contain a cell coordinates in the other numeration system.
Sample test(s)
Output
BC23
R23C55
题意:就是同一种行列表示的两种形式 互相之间的转换 因为一些细节问题错了很多次 其实就是简单地字符串处理 字符串和数字之间的转换
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;
char str[1010];
char ch[22];
int main(){
int n;
scanf("%d", &n);
while(n--){
scanf("%s", str);
bool flag = false;
for(int i = 2; i < strlen(str); ++i){
if(str[0] == 'R' && str[1] - '0' < 10 && (str[i] == 'C')){ //判断是第一种形式还是第二种形式
flag = true;
break;
}
}
if(flag){
bool fi = true; //标记行和列的读取
int a = 0, b = 0;
for(int i = 1; i < strlen(str); ++i){
if(str[i] == 'C'){ //开始去读列
fi = false;
continue;
}
if(fi){ //行转换数字
a = a * 10 + (str[i] - '0');
}
else{ //列转换数字
b = b * 10 + (str[i] - '0');
}
}
int k = 0;
while(b){
int c = b % 26; //转换成相应字母
b /= 26;
if(c == 0){
c += 26;
b -= 1;
}
ch[k++] = c + 'A' - 1;
}
for(int i = k-1; i >= 0; --i){
printf("%c", ch[i]);
}
printf("%d\n", a);
}
else{
bool fi = true;
int a = 0, b = 0;
for(int i = 0; i < strlen(str); ++i){
if(str[i] - '0' < 10){ //开始去读列
fi = false;
}
if(fi){
a = a * 26 + (str[i] + 1 - 'A'); //转换数字
}
else{
b = b * 10 + (str[i] - '0'); //转换数字
}
}
printf("R%dC%d\n", b, a);
}
}
return 0;
}
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.
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.
题意:大概就是给出正多边形上三个点的坐标 求正多边形的面积
做这道题的感触很深 因为真的是感觉数学不够用 后面再别人的博客学习了一下 就是数学方面不过关 错过了第一次cfAK的机会 做算法的还是需要一定的数学基础的
闲话不多说 解题步骤献上
由于是确定是正多边形,所以一定存在外接圆.所以可以分为如下几步:
海伦公式: p=(a+b+c)/2 S=√p(p-a)(p-b)(p-c)
1.求外接圆半径r=abc/4S
2.由余弦定理求出三个圆心角ang[3]
(要注意的是,有可能有三个点在同一段半圆弧上,这是第三个圆心角应该用2π-ang[0]-ang[1], 所以干脆全部都是ang[2]=2π-ang[0]-ang[1])
3.求这三个角的最大公约数为A, 那么这就是一个正2π/A边形.
4.一个小三角形的面积S=1/2·r * r * sinA
5.nS即为所求.
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double PI = 3.1415926535;
const double ERR = 0.01;
double dist(double x0, double x1, double y0, double y1);
bool feq(double a, double b);
double fgcd(double a, double b);
int main(){
pair<double, double> po[3];
for(int i = 0; i < 3; ++i){
scanf("%lf%lf", &po[i].first, &po[i].second);
}
double len[3];
for(int i = 0; i < 3; ++i){
len[i] = dist(po[i].first, po[(i+1)%3].first, po[i].second, po[(i+1)%3].second);
}
double p = (len[0] + len[1] + len[2]) / 2; //海伦公式: p=(a+b+c)/2
double s = sqrt(p * (p-len[0]) * (p-len[1]) * (p-len[2]));//海伦公式: S=√p(p-a)(p-b)(p-c)
double r = len[0] * len[1] * len[2] / (s * 4); //求外接圆半径r=abc/4S
double ang[3];
for(int i = 0; i < 3; ++i){ //由余弦定理求出三个圆心角ang[3]
ang[i] = acos(1 - len[i]*len[i] / (2 * r * r));
}
ang[2] = 2 * PI - ang[0] - ang[1]; //有可能有三个点在同一段半圆弧上,这是第三个圆心角应该用2π-ang[0]-ang[1]
double unita = 0;
for(int i = 0; i < 3; ++i){ //求这三个角的最大公约数为unita, 那么这就是一个正2π/unita边形
unita = fgcd(unita, ang[i]);
}
printf("%.6lf\n", r * r * sin(unita) * PI / unita); //S=1/2·r * r * sinA * n
return 0;
}
double dist(double x0, double x1, double y0, double y1){
return sqrt((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
}
bool feq(double a, double b){
return fabs(a-b) < ERR;
}
double fgcd(double a, double b){
if(feq(a, 0)){
return b;
}
if(feq(b, 0)){
return a;
}
return fgcd(b, fmod(a, b));
}
Codeforces Beta Round #1
标签:
原文地址:http://blog.csdn.net/u012431590/article/details/45691555