zoj3647

像我这种弱比,十一不能回家,中秋不能回家的弱比,才会在这里默默的刷题,我擦

昨天zoj月赛,坑死爹了


ZOJ Problem Set - 3647
Gao the Grid
Time Limit: 2 Seconds Memory Limit: 65536 KB

A n * m grid as follow:




Count the number of triangles, three of whose vertice must be grid-points.
Note that the three vertice of the triangle must not be in a line(the right picture is not a triangle).


Input

The input consists of several cases. Each case consists of two positive integers n and m (1 ≤ n, m ≤ 1000).
Output

For each case, output the total number of triangle.
Sample Input
1 1
2 2
Sample Output
4
76
hint

hint for 2nd case: C(9, 3) - 8 = 76


yy出了想法,想法有些问题,还有搞的重复了好多

然后今天看了woshi250hua大牛的解题报告,修改了代码


然后自认为没错了,还是一直wa,

然后我就改了改输出 %I64d  ->%lld 

就过了,坑爹啊

中秋节木有妹子陪,也木有月饼吃,哎。。。苦逼的日子


#include <cstdio>
#include 
<cstdlib>
#include 
<cstring>
#include 
<cmath>
#include 
<ctime>
#include 
<cassert>
#include 
<iostream>
#include 
<sstream>
#include 
<fstream>
#include 
<map>
#include 
<set>
#include 
<vector>
#include 
<queue>
#include 
<algorithm>
#include 
<iomanip>
#define maxn 1010
#define LL long long
using namespace std;
LL f[maxn][maxn];
LL num[maxn];
LL totpoint,sum;
LL n,m;
int gcd(int a,int b)
{
    
if(b==0return a;
    
else return gcd(b,a%b);
}
void work()
{
    memset(num,
0,sizeof(num));
    num[
0]=num[1]=num[2]=0;
    
for(int i=3; i<=1002; i++)
        
if(i-1&&i-2)
            num[i] 
= i * (i - 1* (i - 2/ 6;
}
int main()
{
    memset(f,
0,sizeof(f));
    
for(int i=1; i<=1002; i++)
    {
        
for(int j=1; j<=1002; j++)
            f[i][j]
=gcd(i,j)-1;
    }
    work();
    
while(scanf("%I64d%I64d",&n,&m)!=EOF)
    {

        totpoint
= (n+1* (m+1);
        sum 
= totpoint * ( totpoint - 1 ) * (totpoint - 2/ 6 ;

        sum 
-= (m+1)*(num[n+1]);
        sum 
-= (n+1)*(num[m+1]);
        
for(int i=1;i<=n;i++)
        
for(int j=1;j<=m;j++)
        {
           sum 
-=  f[i][j]*(n+1-i)*(m+1-j)*2;
        }
        printf(
"%lld\n",sum);
    }
    
return 0;
}


posted on 2012-09-30 09:42 jh818012 阅读(146) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年7月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

导航

统计

常用链接

留言簿

文章档案(85)

搜索

最新评论