LA 4123 - Glenbow Museum
这道题可以用递推做,但是没有必要
首先说长度为L
假设R的个数为x,O的个数为y,那么x+y=L而且x-y=4
当L为奇数和小于4的时候肯定不可以
由于O不能相邻 可以假设O 的数目和R一样多,交叉排放。然后从这些O中
去掉4个
1,R开头的情况 C(x,4)
2,O开头的情况C(x-1,4)
然后两种情况相加即可
代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue> #define ll long long
using namespace std; ll C(int n,int m)
{
ll tmp=1;
for(int i=0;i<m;++i)
tmp=tmp*(n-i);
for(int i=1;i<=m;++i)
tmp=tmp/i;
return tmp;
}
int main()
{
//freopen("data.in","r",stdin);
int ca=0;
int n;
while(cin>>n)
{
++ca;
if(!n) break;
cout<<"Case "<<ca<<": ";
if(n<4||n%2==1)
cout<<"0"<<endl;
else
cout<<C((n+4)/2,4)+C((n+4)/2-1,4)<<endl;
}
return 0;
}
LA 4123 - Glenbow Museum的更多相关文章
- UVALive 4123 Glenbow Museum (组合数学)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 易得,当n为奇数或者n<3时,答案为0,否则该序列中必定有(n+4)/2个R ...
- LA 4123 (计数 递推) Glenbow Museum
题意: 这种所有边都是垂直或水平的多边形,可以用一个字符串来表示,一个270°的内角记作O,一个90°的内角记作R. 如果多边形内存在一个点,能看到该多边形所有的点,则这个多边形对应的序列是合法的.这 ...
- UVa1073 Glenbow Museum
可以把R看成顺时针转90°,O看成逆时针转270° 设R有x个,则180*(n-2)=90*x+270*(n-x) 解得R有(n+4)/2个 O有(n-4)/2个 所以n<4或者n是奇数时无解. ...
- leggere la nostra recensione del primo e del secondo
La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...
- Le lié à la légèreté semblait être et donc plus simple
Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
- Mac OS使用ll、la、l等ls的别名命令
在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...
- UVALive - 2965 Jurassic Remains (LA)
Jurassic Remains Time Limit: 18000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Sub ...
随机推荐
- mysql 权限控制
1.mysql的权限是,从某处来的用户对某对象的权限. 2.mysql的权限采用白名单策略,指定用户能做什么,没有指定的都不能做. 3.权限校验分成两个步骤: a.能不能连接,检查从哪里来,用户名和密 ...
- number-of-segments-in-a-string
https://leetcode.com/problems/number-of-segments-in-a-string/ package com.company; class Solution { ...
- Openfire 是怎么存离线消息
原文:http://myopenfire.com/article/getarticle/26 1.openfire默认怎么存离线消息 在默认情况下,不添加任何插件的情况下,当用户不在线,对于发送给 ...
- Java集合的Stack、Queue、Map的遍历
Java集合的Stack.Queue.Map的遍历 在集合操作中,常常离不开对集合的遍历,对集合遍历一般来说一个foreach就搞定了,但是,对于Stack.Queue.Map类型的遍历,还是有一 ...
- [C++]访问控制与继承(public,protect,private) 有时间再整理!!!
http://www.cnblogs.com/chio/archive/2007/06/11/779408.html http://www.cnblogs.com/SelaSelah/archive/ ...
- 使用RestTemplate Spring安全认证
使用RestTemplate Spring安全认证 java spring 认证authentication 安全spring-security 我有提供2个独立的一整套服务2 Spring的web应 ...
- 工作了3年的JAVA程序员应该具备什么技能?(zhuan)
http://www.500d.me/article/5441.html **************************************** 来源:五百丁 作者:LZ2016-03-18 ...
- Spring3.1新特性
一.Spring2.5之前,我们都是通过实现Controller接口或其实现来定义我们的处理器类. 二.Spring2.5引入注解式处理器支持,通过@Controller 和 @RequestMa ...
- jsonp跨域原理
Jsonp原理: 首先在客户端注册一个callback (如:'jsoncallback'), 然后把callback的名字(如:jsonp1236827957501)传给服务器.注意:服务端得到ca ...
- jquery学习笔记1
(1) jQuery的Id选择器: $("#btnShow") (2) 事件绑定函数 bind() $("#btnAdd").bind("click& ...