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

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

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #define maxn 1000
  5. #define ll long long
  6. using namespace std;
  7.  
  8. ll c[maxn][maxn];
  9. int n,m;
  10. ll gcd(ll a,ll b)
  11. {
  12. if(b==) return a;
  13. else return gcd(b,a%b);
  14. }
  15.  
  16. ll cnr(int n,int r)
  17. {
  18. if(n<r)return ;
  19. if(n-r<r)r=n-r;
  20. int i,j;
  21. ll ret=;
  22. for(i=,j=;i<r;i++)
  23. {
  24. ret*=(n-i);
  25. for(;j<=r&&ret%j==;j++)ret/=j;
  26. }
  27. return ret;
  28. }
  29.  
  30. int main()
  31. {
  32. while(scanf("%d%d",&n,&m)!=EOF)
  33. {
  34. ll ans=cnr((n+)*(m+),);
  35. if(n+>=)
  36. ans-=(m+)*cnr(n+,);
  37. if(m+>=)
  38. ans-=(n+)*cnr(m+,);
  39. for(int i=; i<=n; i++)
  40. {
  41. for(int j=; j<=m; j++)
  42. {
  43. if(gcd(i,j)-)
  44. {
  45. ans-=(gcd(i,j)-)*(n-i+)*(m-j+)*;
  46. }
  47. }
  48. }
  49. printf("%lld\n",ans);
  50. }
  51. return ;
  52. }

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. localStorage存储JSON对象的小方法

    有时候,我们需要将数据存储到sessionStorage和localStorage中,这样做的好处有: 1 缓存数据 2 减少对内存的占用 但是,storage只能存储字符串的数据,对于JS中常用的数 ...

  2. fork安全的gettid高效实现

    进程有id,可以通过getpid()获得,线程也有id,但是glibc没有提供封装.需要自己发出系统调用.在关键路径,系统调用还是对性能有影响的.因此我们可以想到类似glibc对getpid做的cac ...

  3. C#Linq的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. GridView and DropDownList

    <form id="form1" runat="server"> <div> <asp:GridView runat=" ...

  5. .Net使用SSH.NET通过SSH访问Linux主机

    使用了SSH.NET库,添加引用dll至项目,以下代码显示了点击按钮后SSH链接Linux主机执行命令并返回命令执行结果 protected void btnExcute_Click(object s ...

  6. [php基础]PHP Form表单验证:PHP form validator使用说明

    在PHP网站开发建设中,用户注册.留言是必不可少的功能,用户提交的信息数据都是通过Form表单提交,为了保证数据的完整性.安全性,PHP Form表单验证是过滤数据的首要环节,PHP对表单提交数据的验 ...

  7. Lesson 4: Know Your Tools

    Lesson 4: Know Your Tools "差劲的人

  8. c - 十六进制 转 十进制

    考虑到举一反三,这里顺便上完整代码,顺便可以考虑实现R进制和十进制的转换. 完整代码: #include <stdio.h> #include <math.h> double ...

  9. ESXi控制台TSM:弥补vSphere Client不足

    当vSphere Client不能完成某些任务时,主机的ESXi控制台及其技术支持模式(TSM)可能能派上用场. ESXi控制台允许管理员执行不能通过vSphere Client进行配置的管理任务,比 ...

  10. javascript代码放置位置对程序的影响

    在编写html文档时,javascript可以放置的位置有两个地方<head>或者<body>,但是放置的地方,会对 JavaScript 代码的正常执行会有一定影响.由于 H ...