UVALive 4123Glenbow Museum

题意:给定一个长度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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值