链接:https://ac.nowcoder.com/acm/contest/6006/D
来源:牛客网
题目描述
根据给出的三角形3条边a, b, c(0 < a, b, c < 100,000),计算三角形的周长和面积。
输入描述:
一行,三角形3条边(能构成三角形),中间用一个空格隔开。
输出描述:
一行,三角形周长和面积(保留两位小数),中间用一个空格隔开,输出具体格式详见输出样例。
示例1
输入
复制
3 3 3
输出
复制
circumference=9.00 area=3.90
海伦公式
-
知道三角形三条边 a , b , c a,b,c a,b,c,用来求面积 S S S
p = ( a + b + c ) / 2 p = (a+b+c)/2 p=(a+b+c)/2
S = p ∗ ( p − a ) ∗ ( p − b ) ∗ ( p − c ) S = \sqrt{p*(p-a)*(p-b)*(p-c)} S=p∗(p−a)∗(p−b)∗(p−c)
double p = (a + b + c) / 2; double area = sqrt((p*(p-a)*(p-b)*(p-c)));
完整代码
#ifdef debug
#include <time.h>
#include "/home/majiao/mb.h"
#endif
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#define MAXN ((int)1e5+7)
#define ll long long
#define INF (0x7f7f7f7f)
#define fori(lef, rig) for(int i=lef; i<=rig; i++)
#define forj(lef, rig) for(int j=lef; j<=rig; j++)
#define fork(lef, rig) for(int k=lef; k<=rig; k++)
#define QAQ (0)
using namespace std;
#define show(x...) \
do { \
cout << "\033[31;1m " << #x << " -> "; \
err(x); \
} while (0)
void err() { cout << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
namespace FastIO{
char print_f[105];
void read() {}
void print() { putchar('\n'); }
template <typename T, typename... T2>
inline void read(T &x, T2 &... oth) {
x = 0;
char ch = getchar();
ll f = 1;
while (!isdigit(ch)) {
if (ch == '-') f *= -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getchar();
}
x *= f;
read(oth...);
}
template <typename T, typename... T2>
inline void print(T x, T2... oth) {
ll p3=-1;
if(x<0) putchar('-'), x=-x;
do{
print_f[++p3] = x%10 + 48;
} while(x/=10);
while(p3>=0) putchar(print_f[p3--]);
putchar(' ');
print(oth...);
}
} // namespace FastIO
using FastIO::print;
using FastIO::read;
int n, m, Q, K;
int main() {
#ifdef debug
freopen("test", "r", stdin);
clock_t stime = clock();
#endif
double a, b, c;
cin >> a >> b >> c;
double p = (a + b + c) / 2;
double area = sqrt((p*(p-a)*(p-b)*(p-c)));
printf("circumference=%.2lf area=%.2lf\n", a+b+c, area);
#ifdef debug
clock_t etime = clock();
printf("rum time: %lf 秒\n",(double) (etime-stime)/CLOCKS_PER_SEC);
#endif
return 0;
}