codeforces_630H. Benches
2016-03-05 16:48
423 查看
H. Benches
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
The city park of IT City contains n east to west paths and n north
to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each
path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100)
— the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
input
5
output
120
这道题我掉了个大坑,就是long
long 的溢出问题,本来以为下面的代码必过,然而痛苦了好一阵子
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
The city park of IT City contains n east to west paths and n north
to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.
The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each
path contains not more than one bench.
Help the park administration count the number of ways to place the benches.
Input
The only line of the input contains one integer n (5 ≤ n ≤ 100)
— the number of east to west paths and north to south paths.
Output
Output one integer — the number of ways to place the benches.
Examples
input
5
output
120
这道题我掉了个大坑,就是long
long 的溢出问题,本来以为下面的代码必过,然而痛苦了好一阵子
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; int main() { int n,i; scanf("%d",&n); long long ans=1; for(i=1;i<=5;i++) { ans*=n*n; n--; } ans/=120; printf("%lld\n",ans); return 0; }明白溢出问题后,就修改了乘法过程。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> using namespace std; int main() { int n; scanf("%d",&n); long long ans; ans=n*(n-1)/2*(n-2)/3*(n-3)/4*(n-4)/5; printf("%lld\n",ans*ans*120); return 0; }
相关文章推荐
- 感受HTML5 Audio API带来的视听盛宴
- CF 615 E Hexagons(找规律)
- 带参数的宏定义
- F - 播放器
- Hust oj 1521 Marshal's Confusion III(整数快速幂)
- 【转】android调试工具DDMS的使用详解
- leetcode 求最大深度 之 递归 总结
- Toast的参数选择
- 蓝桥杯 神奇算式
- 蓝桥杯 历届试题 振兴中华
- LeetCode--172. Factorial Trailing Zeroes
- hdoj--5100--Chessboard(数学推理)
- hdoj--5100--Chessboard(数学推理)
- 有没有必要阅读源码
- 一起talk C栗子吧(第二十回:C语言实例--括号匹配)
- 读书笔记----哲学家们都干了什么
- 整理六百篇web前端知识混总
- gdb笔记
- Spring tool suite 快速创建Spring MVC 项目
- 基础母函数模版