在哈尔滨的寒风中EOJ 3461【组合数学】

http://acm.ecnu.edu.cn/problem/3461/

还是能力不够,不能看出来棋盘足够大时,马是可以到达任何位置的。还是直接看题解怎么说的吧:(http://acm.ecnu.edu.cn/blog/entry/137/

这个2*n时交替到达我是这么理解的,本来就只有两列,应该每行对应两列上的两个位置具有的点对数相同,那么只需考虑一列上的点就好了。手动模拟一下也许就有了答案的结果。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 typedef long long ll;
 7 
 8 ll combina(int a)
 9 {
10     ll ans=0;
11     if(a%2){
12         ans=(a-1)/2;
13         ans*=a;
14     }else{
15         ans=a/2;
16         ans*=(a-1);
17     }
18     return ans;
19 }
20 
21 int main()
22 {
23     int n,m;
24     ll ans=0;
25     while(scanf("%d%d",&n,&m)==2)
26     {
27         if(n==1||m==1) printf("0\n");
28         else if(n==2||m==2){
29             if(n==2){
30                 ans=2*combina(m/2)+2*combina(m-m/2);
31                 printf("%lld\n",ans);
32             }else{
33                 ans=2*combina(n/2)+2*combina(n-n/2);
34                 printf("%lld\n",ans);
35             }
36         }else if(n==3&&m==3) printf("%d\n",combina(8));
37         else{
38             ans=combina(n*m);
39             printf("%lld\n",ans);
40         }
41     }
42     return 0;
43 }

 

posted @ 2017-12-09 19:04  ╰追憶似水年華ぃ╮  阅读(198)  评论(0编辑  收藏  举报