大意:一个R的桌子能否摆下n个半径为r的盘子 要求所有的盘子靠桌子的边缘放置
分析:
两种思路
一种是看这个桌子放这种盘子最多放多少个
一种是把这种盘子n个放在这个桌子上最少需要多大桌子半径
代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 const int maxn = 105; 8 const double PI = 3.14159265358979; 9 10 int eps(double x) { 11 if(fabs(x) < 1e-8) return 0; 12 if(x < 0) return -1; 13 return 1; 14 } 15 16 int main() { 17 int n; 18 double R, r; 19 while(EOF != scanf("%d %lf %lf",&n, &R, &r) ) { 20 if(n == 1) { 21 if(eps(R - r) >= 0) puts("YES"); 22 else puts("NO"); 23 } else if(n == 2) { 24 if(eps(R - 2 * r) >= 0) puts("YES"); 25 else puts("NO"); 26 } else { 27 double x = PI / n; 28 double y = r / sin(x) + r; 29 if(eps(R - y) >= 0) puts("YES"); 30 else puts("NO"); 31 } 32 } 33 return 0; 34 }
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 const int maxn = 105; 8 const double PI = 3.14159265358979; 9 10 int eps(double x) { 11 if(fabs(x) < 1e-8) return 0; 12 if(x < 0) return -1; 13 return 1; 14 } 15 16 int main() { 17 int n; 18 double R, r; 19 while(EOF != scanf("%d %lf %lf",&n, &R, &r) ) { 20 if(eps(R - 2 * r) >= 0) { 21 double x = asin(r / ( R - r ) ); 22 int y = ( int )(( PI + 1e-8) / x); 23 if(y >= n) puts("YES"); 24 else puts("NO"); 25 } else if(eps(R - r) >= 0){ 26 if(n <= 1) puts("YES"); 27 else puts("NO"); 28 } else { 29 puts("NO"); 30 } 31 } 32 return 0; 33 }