zoukankan      html  css  js  c++  java
  • 3505: [Cqoi2014]数三角形

    3505: [Cqoi2014]数三角形

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 1324  Solved: 807
    [Submit][Status][Discuss]

    Description

    给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个。下图为4x4的网格上的一个三角形。

    注意三角形的三点不能共线。

    Input

    输入一行,包含两个空格分隔的正整数m和n。

    Output


    输出一个正整数,为所求三角形数量。

    Sample Input


    2 2

    Sample Output

    76


    数据范围
    1<=m,n<=1000

    HINT

     

    Source

    弱弱的我,不会推式子,只能这样搞了。

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    ll ans,t,c[4];
    ll C(int n,int k){
        c[0]=1;
        for(int i=1;i<=k;i++)  c[i]=c[i-1]*(n-i+1)/i;
        return c[k];
    }
    int n,m;
    void solve(){
        ans+=C(n*m,3);//总数 
        ans-=m*C(n,3);//减去同一行 
        ans-=n*C(m,3);//减去同一列 
        for(int i=1;i<n;i++){//再减去在斜直线上的 
            for(int j=1;j<m;j++){
                t=__gcd(i,j)+1;
                if(t>2) ans-=(t-2)*(n-i)*(m-j)*2;
            }
        }
    }
    int main(){
        scanf("%d%d",&n,&m);n++;m++;
        solve();
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    2017年6月笔记
    2017年5月笔记
    2017年4月笔记
    转发:i p _ f o r w a r d函数
    IP分组
    IP协议首部结构介绍
    IP:网际协议
    sed工具使用
    正则表达式匹配
    TCP的半连接
  • 原文地址:https://www.cnblogs.com/shenben/p/6287097.html
Copyright © 2011-2022 走看看