POJ 1005

来源:互联网 发布:mac book pro型号大全 编辑:程序博客网 时间:2024/05/29 12:12
/* * poj_1005.c * accepted */#include <stdio.h>#include <stdlib.h>#include <string.h>#define PI (3.14159265)#define EPS (1e-6)#define EROSION_YEAR (50)#define LINE_SIZE (70)static int poj_1005 (double d1, double d2);int main (int argc, char * argv[]){int i;int n_t;double d_t1, d_t2;char str[LINE_SIZE];char (* buf_out)[LINE_SIZE] = NULL;scanf ("%d", &n_t);buf_out = (char (*)[LINE_SIZE]) malloc ( n_t * LINE_SIZE);buf_out[0][0] = '\0';for (i=1; i<=n_t; i++){scanf ("%lf%lf", &d_t1, &d_t2);sprintf (str, "Property %d: This property will begin eroding in year %d.\n", i, poj_1005 (d_t1, d_t2));strcat (buf_out[0], str);}printf ("%sEND OF OUTPUT.\n", buf_out);if ( buf_out){free (buf_out);}return 0;}static int poj_1005 (double d1, double d2){int i=0;while (PI*(d1*d1+d2*d2) - 2*EROSION_YEAR*i > EPS){i++;}return i;}