http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837

先求出从所有点随机找出三个点的组合数,然后去掉共线的,平行好去掉,斜线就需要枚举矩形,也就是枚举两个端点形成向量。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1000
#define ll long long
using namespace std; ll c[maxn][maxn];
int n,m;
ll gcd(ll a,ll b)
{
if(b==) return a;
else return gcd(b,a%b);
} ll cnr(int n,int r)
{
if(n<r)return ;
if(n-r<r)r=n-r;
int i,j;
ll ret=;
for(i=,j=;i<r;i++)
{
ret*=(n-i);
for(;j<=r&&ret%j==;j++)ret/=j;
}
return ret;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
ll ans=cnr((n+)*(m+),);
if(n+>=)
ans-=(m+)*cnr(n+,);
if(m+>=)
ans-=(n+)*cnr(m+,);
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(gcd(i,j)-)
{
ans-=(gcd(i,j)-)*(n-i+)*(m-j+)*;
}
}
}
printf("%lld\n",ans);
}
return ;
}

zoj 3647 Gao the Grid的更多相关文章

  1. ZOJ 3647 Gao the Grid dp,思路,格中取同一行的三点,经典 难度:3

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 三角形的总数=格子中任取3个点的组合数-同一横行任取3个点数目-同一纵行 ...

  2. ZOJ 3780 Paint the Grid Again(隐式图拓扑排序)

    Paint the Grid Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N × N cel ...

  3. ZOJ 3781 Paint the Grid Reloaded(BFS+缩点思想)

    Paint the Grid Reloaded Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N rows ...

  4. ZOJ 3781 Paint the Grid Reloaded(BFS)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Leo has a grid with N rows an ...

  5. zoj 3672 Gao The Sequence

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意 ...

  6. zoj 3647 智商题

    此题就是求格点中三角形的个数. 就是找出三点不共线的个数. n*m的矩形中有(n+1)*(m+1)个格点. 选出三个点的总个数为:C((n+1)*(m+1),3). 减掉共线的情况就是答案了. 首先是 ...

  7. ZOJ 3781 - Paint the Grid Reloaded - [DFS连通块缩点建图+BFS求深度][第11届浙江省赛F题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3781 Time Limit: 2 Seconds      Me ...

  8. ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds      Me ...

  9. ZOJ 3408 Gao

    ZOJ题目页面传送门 给定一个有向图\(G=(V,E),n=|V|,m=|E|\)(可能有重边和自环,节点从\(0\)开始编号),以及\(q\)组询问,对于每组询问你需要回答有多少条从节点\(0\)开 ...

随机推荐

  1. bin

    动态链接库(Dynamic Link Library或者Dynamic-link library,缩写为DLL),是微软公司在微软视窗操作系统(即Windows操作系统)中实现共享函数库概念的一种方式 ...

  2. jQuery表单验证以及将表单序列化为json对象小练习

    jquery表单验证(非实时验证),同时,将表单序列化为json对象提交表单. <!DOCTYPE html> <html lang="en"> <h ...

  3. Oracle V$SESSION

    SADDR session address SID session identifier 常用于链接其他列 SERIAL# SID有可能会重复,当两个session的SID重复时,SERIAL#用来区 ...

  4. 如何实现数字lcd显示效果(原创)

    如题,我最先想到的是找一种字体,然后来显示lcd的效果,但是字体又无法满足有空位的时候那个暗灰色的文字的效果,如下所示 就是前三位那些灰色的888,因为你设置数值的时候只能是从0-9的数字,而这灰色的 ...

  5. Freemarker常用技巧(三)

    freemarker模板解析过程 例如:一个freemarker表达式<body> ${hello} </body>,会被解析成三个部分,分别是<body>${he ...

  6. Bzoj3990 [SDOI2015]排序

    Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 651  Solved: 338 Description 小A有一个1-2^N的排列A[1..2^N], ...

  7. oracle的concat的用法

    select concat( concat( concat( ( select area_name from ec_area where area_id ), ( select area_name f ...

  8. Linux最大文件打开数

    介绍 在Linux下有时会遇到Socket/File : Can't open so many files的问题.其实Linux是有文件句柄限制的,而且Linux默认一般都是1024(阿里云主机默认是 ...

  9. Genymotion 模拟器 VirtualBox

    准备 介绍: 1.Genymotion安卓模拟器其实不是普通的模拟器,严格来说,genymotion是虚拟机,被网传定义为模拟器,加载APP的速度比较快,操作起来也很流畅.2.Genymotion依赖 ...

  10. Myeclipse中点(.)不出来方法或者属性?