P1057 传球游戏 - 完美错解
//作者:pb2 博客:https://www.luogu.com.cn/blog/pb2/ 或 http://www.cnblogs.com/p2blog
//博客新闻1:"WPS开机自启,每10秒 会访问一次百度 的IP(36.152.44.95/)!"
//新闻二:"三种安全程度的百度!(其中两种"不安全")"
#include <iostream>
using namespace std;
int main() {
int n, m;//n=people num;m=give ball num
cin >> n >> m;
if (m == 1) {//special m
cout << 0;
return 0;
}
else if (m == 2) {
cout << n - 1;
return 0;
}
else if (m == 3) {
cout << (n - 1) * (n - 2);
return 0;
}//special ways
n--;//a person can not give ball to himself(so -1)
int en = n - 1, now = 1;//except o=one=1(xiao man)(so -1 again)
long long o = 1, e = 0;//o=one=1(xiao man) e=else=2,3,4... now=m (now)
long long obefore = o;//like temp in the function "swap()"
while (now != m - 2) {
o = e;
e = en * e + n * obefore;
obefore = o;
now++;
}
cout << o * n + e * en;
return 0;
}
最新文章
- windows10的第一天使用总结
- [java] 汇率换算器实现(1)
- Adding New Functions to MySQL(User-Defined Function Interface UDF、Native Function)
- crossplatform---Nodejs in Visual Studio Code 08.IIS
- 简单使用Dos命令关闭计算机
- python:时间处理模块
- 在公网上布署Web Api的时候,不能调用,返回404
- 禁用谷歌字体解决WordPress访问速度过慢问题
- spoj TSUM - Triple Sums fft+容斥
- Directx11学习笔记【十四】 使用最新的Effect框架和SDK
- 【Machine Learning in Action --5】逻辑回归(LogisticRegression)从疝气病预测病马的死亡率
- 05_NoSQL数据库之Redis数据库:Redis的常用命令,键值相关命令和服务器相关命令
- 阿里云服务器公网Ip外网无法访问
- Burnside引理的感性证明
- Python之列表推导式
- ActiveMQ producer 流量控制
- 节点的启动与关闭 ros::init()解析(c++)
- (C/C++学习笔记) 十. 函数
- Laravel 5.4: 特殊字段太长报错
- Oracle存储过程中调用DBLink同义词出现错误:PLS-00201: 必须声明标识符