題意:對於一個邊平行於座標軸的多邊形,我們可以用一個由R和O組成的序列來描述它:從某個頂點開始按照逆時針順序走,碰到一個90°的內角記R;碰到一個270°的內角記O。這樣的序列稱爲角度序列。定義星型多邊形爲多邊形中存在一個點可以看到多邊形邊界上每一個點。現在給定正整數n,求有多少個長度爲L的角度序列至少可以對應一個星型多邊形。其中多邊形的每條邊長任意。
思路:星型多邊形值在多邊形內存在一點,能看到多邊形邊上的任何一點。根據這個定義就可以畫畫圖就可以得到,R比O多四個,且O不能連續出現
問題轉化成L的序列中R比O多四個,且O不能連續出現,所以用隔板法,這樣O就不連續了,還有就是收尾連續的情況,單獨拿出來計數一下。
計算C(n,m)的時候要按照遞增計算防止爆long long。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
#define rep(i,n) for ( int i=0; i< int(n); i++ )
using namespace std;
typedef long long ll;
#define X first
#define Y second
#define PB push_back
#define MP make_pair
typedef pair<int,int> pii;
template <class T>
inline bool RD(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
template <class T>
inline void PT(T x) {
if (x < 0) putchar('-') ,x = -x;
if (x > 9) PT(x / 10);
putchar(x % 10 + '0');
}
ll C(ll n, ll m) {
if( m < 0 ) return 0;
ll ans = 1;
for(ll i = 1 ; i <= m; i ++ )
ans = ans * (n - m + i) / i ;
return ans ;
}
int main() {
ll L;
int cas = 0;
while( RD(L) ) {
if( L == 0 ) break ;
ll ans = 2LL * C((L+4)/2 - 1, (L-4)/2 - 1) + C( (L+4)/2 - 1, (L-4)/2 ) ;
if( L <= 3 || L & 1 ) ans = 0;
printf("Case %d: %lld\n", ++ cas, ans) ;
}
}