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[];
ll C(int n,int k){
c[]=;
for(int i=;i<=k;i++) c[i]=c[i-]*(n-i+)/i;
return c[k];
}
int n,m;
void solve(){
ans+=C(n*m,);//总数
ans-=m*C(n,);//减去同一行
ans-=n*C(m,);//减去同一列
for(int i=;i<n;i++){//再减去在斜直线上的
for(int j=;j<m;j++){
t=__gcd(i,j)+;
if(t>) ans-=(t-)*(n-i)*(m-j)*;
}
}
}
int main(){
scanf("%d%d",&n,&m);n++;m++;
solve();
printf("%lld\n",ans);
return ;
}

3505: [Cqoi2014]数三角形的更多相关文章

  1. BZOJ 3505: [Cqoi2014]数三角形 数学

    3505: [Cqoi2014]数三角形 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...

  2. Bzoj 3505: [Cqoi2014]数三角形 数论

    3505: [Cqoi2014]数三角形 Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits   Description

  3. bzoj 3505: [Cqoi2014]数三角形 组合数学

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 478  Solved: 293[Submit][Status ...

  4. BZOJ 3505: [Cqoi2014]数三角形( 组合数 )

    先n++, m++ 显然答案就是C(3, n*m) - m*C(3, n) - n*C(3, m) - cnt. 表示在全部点中选出3个的方案减去不合法的, 同一行/列的不合法方案很好求, 对角线的不 ...

  5. BZOJ 3505: [Cqoi2014]数三角形 [组合计数]

    3505: [Cqoi2014]数三角形 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注意三角形的三点不能共线. 1<=m,n<=1000 $n++ m++$ $ans ...

  6. BZOJ 3505 [Cqoi2014]数三角形

    3505: [Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形.注意三角形的三点不能共线. Input ...

  7. bzoj 3505 [Cqoi2014]数三角形(组合计数)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题意] 在n个格子中任选3点构成三角形的方案数. [思路] 任选3点-3点共线 ...

  8. BZOJ 3505 [Cqoi2014]数三角形(组合数学)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题目大意] 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注 ...

  9. 【BZOJ】3505: [Cqoi2014]数三角形

    题意 \(n * m(1 \le n, m \le 1000)\)的网格,求顶点在格点上三角形的个数. 分析 假设\(n \le m\) \(ans = \binom{(n+1) * (m+1)}{3 ...

随机推荐

  1. UVALive - 3942 Remember the Word

    input 字符串s  1<=len(s)<=300000 n 1<=n<=4000 word1 word2 ... wordn 1<=len(wordi)<=10 ...

  2. Arch: Configurations

    the original purpose is to show the steps needed to setup i3 in vbox.. easy. alright, it is a bit mi ...

  3. 拓扑排序<反向拓扑+有向环的判断>

    题目链接 #include <set> #include <map> #include <cmath> #include <queue> #includ ...

  4. Javascrpit学习之路一——基础知识

    1.DOM 文档对象模型 定义:一个与系统平台和编程语言无关的接口,程序和脚本可以通过这个接口动态的访问和修改文档的内容.结构和样式. 2.Javascript 区分大小写.弱类型语言 变量小写:va ...

  5. js 基础对象一

    JavaScript 通常用于操作 HTML 元素. Document元素 每个载入浏览器的 HTML 文档都会成为 Document 对象. Document 对象使我们可以从脚本中对 HTML 页 ...

  6. Universal-Image-Loader分析:

    Android-Universal-Image-Loader是一个开源的UI组件程序,该项目的目的是提供一个可重复使用的仪器为异步图像加载,缓存和显示.权限: <uses-permission ...

  7. HDU 2609 How many

    最小表示法+Map或者字典树,最小表示法找了个模板,还没学习呢... #include<cstdio> #include<cstring> #include<cmath& ...

  8. GB2312、Unicode编码等

    抛出问题: 我在CPP文件中,打算输出一行阿拉伯字符:

  9. If only it could be all the same like we first me

    为什么 你当时对我好 Why? You nice to me at that time. 又为什么 现在变得冷淡了 Why? Now you give a cold shoulder to me. 我 ...

  10. android4.0蓝牙使能的详细解析(转)

    源:http://www.cnblogs.com/xiaochao1234/p/3818193.html 本文详细分析了android4.0 中蓝牙使能的过程,相比较android2.3,4.0中的蓝 ...