2014
03-06

# Build a Fence

There is a wall in your backyard. It is so long that you can’t see its endpoints. You want to build a fence of length L such that the area enclosed between the wall and the fence is maximized. The fence can be of arbitrary shape, but only its two endpoints may touch the wall.

The input consists of several test cases.
For every test case, there is only one integer L (1<=L<=100), indicating the length of the fence.
The input ends with L=0.

The input consists of several test cases.
For every test case, there is only one integer L (1<=L<=100), indicating the length of the fence.
The input ends with L=0.

1
100
0

0.16
1591.55

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const double PI = acos(-1.0);
int n;

int main() {
while (scanf("%d", &n) != EOF) {
if (n == 0) break;
printf("%.2lf\n", (n / PI) * (n / PI) * PI * 0.5);
}
return 0;
}

1. 老实说，这种方法就是穷举，复杂度是2^n，之所以能够AC是应为题目的测试数据有问题，要么数据量很小，要么能够得到k == t，否则即使n = 30，也要很久才能得出结果，本人亲测

2. 为什么for循环找到的i一定是素数叻，而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak，而你每次取余都用的是原来的m，也就是n

3. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮