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;
}ios

相關文章
相關標籤/搜索