算法竞赛入门经典 写题笔记(第二章 数学基础)
Chess Queen
组合数
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MAXN 100010
using namespace std;
int n,m;
int main()
{
#ifndef ONLINE_JUDGE
freopen("ce.in","r",stdin);
#endif
while(scanf("%d%d",&n,&m)==2)
{
if(n==0&&m==0) break;
long long cur_ans=0;
if(n>m) swap(n,m);
for(int i=1;i<=n-1;i++) cur_ans+=1ll*i*(i-1);
// printf("cur_ans=%lld\n",cur_ans);
printf("%lld\n",1ll*(cur_ans)*4+1ll*n*m*(n+m-2)+1ll*2*(m-n+1)*n*(n-1));
}
return 0;
}
例题2 Triangle Counting
例题3 Cheerleaders
例题4 Exploring Pyramids
例题5 Investigating Div-Sum Property
例题6 Glenbow Museum
例题6 Series-Parallel Networks
例题7 Always an integer
例题8 GCD - Extreme (II)
例题9 Code Feat
例题10 Emoogle Grid
例题11 Playing With Stones
例题12 Treblecross
例题13 Tribles
例题14 Joining with Friend
例题15 Expect the Expected
例题16 Race to 1
例题17 Arif in Dhaka (First Love Part 2)
例题18 Leonardo's Notebook
例题19 Find the Permutations
例题20 Pixel Shuffle
例题21 Recurrences
例题22 Cellular Automaton
例题23 Back to Kernighan-Ritchie
例题24 Square
例题25 solve It

更多精彩