题意:给定一个长度L。求满足'O'.'R'表示的长度为L的边平行于坐标轴的多边形有多少种。并且在多边形内的任意一点都能直接看到每个顶点。
分析:《算法竞赛入门经典训练指南》数学基础例题6。在分析完数量差是4之后,我是直接用的组合数求,不是像刘汝佳一样的递推。
代码:
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=1000010;
const int MAX=151;
const int MOD1=1000007;
const int MOD2=100000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000009;
const ll INF=10000000010;
typedef unsigned long long ull;
ll C(int n,int m) {
ll s=1,t=1;
if (m>n-m) m=n-m;
for (int i=1;i<=m;i++) {
s*=(ll)(n-i+1);t*=(ll)i;
}
return s/t;
}
int main()
{
int l,ca=0;
while (scanf("%d", &l)&&l) {
if ((l<4)||(l&1)) { printf("Case %d: 0\n", ++ca);continue ; }
if (l==4) { printf("Case %d: 1\n", ++ca);continue ; }
printf("Case %d: %lld\n", ++ca, 2*C((l-4)/2+3,(l-4)/2-1)+C((l-4)/2+3,(l-4)/2));
}
return 0;
}