ZOJ 3647 Gao the Grid(居然是暴力)
来源:互联网 发布:免费的群发软件 编辑:程序博客网 时间:2024/05/01 22:38
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 integersn and m (1 ≤ n, m ≤ 1000).
Output
For each case, output the total number of triangle.
Sample Input
1 12 2
Sample Output
476
hint
hint for 2nd case: C(9, 3) - 8 = 76
题目意思 : 给你矩形长度,求在里面取3个点,问可以组成三角形的个数?
一共有(n+1)*(m+1)个点,去3个
然后减去同行取3个,同列取3个;
最后减去左斜和右斜的,这种情况居然是枚举三角形的长高!!!!!
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#define eps 1e-8using namespace std;#define N 10005typedef long long ll;ll L(ll x){return (ll)(x*(x-1)*(x-2)/6);}ll gcd(ll n,ll m){if(m==0) return n;return gcd(m,n%m);}int main(){ll i,j,n,m;while(~scanf("%lld%lld",&n,&m)){ n++; m++;ll ans=L(n*m)-L(n)*m-L(m)*n;for(i=2;i<n;i++)for(j=2;j<m;j++){ll temp=gcd(i,j)-1;temp=temp*(n-i)*(m-j)*2;ans-=temp; } printf("%lld\n",ans);} return 0;}
0 0
- ZOJ 3647 Gao the Grid(居然是暴力)
- Zoj 3647 Gao the Grid (数论?)
- ZOJ 3647 Gao the Grid
- ZOJ 3647 Gao the Grid
- zoj 3647 Gao the Grid
- ZOJ-3647 Gao the Grid
- ZOJ 3647 Gao the Grid
- ZOJ 3647 Gao the Grid (计数 + pick定理)
- Zoj 3647 Gao the Grid ( 2012年浙大9月月赛)组合数学
- zoj 3647 Gao the Grid(矩阵对角线三点共线)
- zoj 3647 Gao the Grid (求三角形的个数,困难)
- ZOJ 3648 Gao the Grid II
- Gao the Grid zoj3647(数论)
- zoj 3672 Gao The Sequence
- zoj - 3672 - Gao The Sequence
- ZOJ 3672 Gao The Sequence
- HDU 5073 Galaxy(居然是暴力)
- ZOJ 3535 Gao the String II
- 项目四大奖赛计分
- Android开发中这些小技巧你都知道吗?(二)
- 【bzoj】【100题 留念】
- 题目1000:计算a+b
- 12306客服电话
- ZOJ 3647 Gao the Grid(居然是暴力)
- CentOS6安装内核源码
- 使用qq第三方登录常见错误码信息及解决方法
- 设计模式开篇
- google多线程面试题
- TI-Light_switch学习
- 12306人工客服电话 是多少
- nyoj 题目477 A+B Problem III
- Java源码阅读的真实体会