码迷,mamicode.com
首页 > 其他好文 > 详细

COJ 0020 30201象棋中的皇后

时间:2015-07-10 11:15:16      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

题解:其实是一道计数好题。。。

先得有个公式:多项平方和公式:1^2+2^2+3^2+…+n^2=n(n+1)(2n+1)/6 

竖着的、横着的都还好。对于对角线,窝萌只要注意到长度的变化即可,别忘了有两条对角线!

然后算一下发现并不会溢出,所以就这样了。。。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<queue>
 6 #include<cstring>
 7 #define PAU putchar(‘ ‘)
 8 #define ENT putchar(‘\n‘)
 9 using namespace std;
10 inline unsigned long long read(){
11     unsigned long long x=0,sig=1;char ch=getchar();
12     while(!isdigit(ch)){if(ch==-) sig=-1;ch=getchar();}
13     while(isdigit(ch)) x=10*x+ch-0,ch=getchar();
14     return x*sig;
15 }
16 inline void write(unsigned long long x){
17     if(x==0){putchar(0);return;}if(x<0) putchar(-),x=-x;
18     int len=0;unsigned long long buf[15];while(x) buf[len++]=x%10,x/=10;
19     for(int i=len-1;i>=0;i--) putchar(buf[i]+0);return;
20 }
21 unsigned long long n,m;
22 void init(){
23     n=read();m=read();
24     if(n>m) swap(n,m);
25     write(n*m*(n+m-2)+2*n*(n-1)*(3*m-n-1)/3);
26     return;
27 }
28 void work(){
29     return;
30 }
31 void print(){
32     return;
33 }
34 int main(){
35     init();work();print();return 0;
36 }

 

 

  

COJ 0020 30201象棋中的皇后

标签:

原文地址:http://www.cnblogs.com/chxer/p/4635019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!