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. js的深拷贝和浅拷贝

    一.数组的深浅拷贝 在使用JavaScript对数组进行操作的时候,我们经常需要将数组进行备份,事实证明如果只是简单的将它赋予其他变量,那么我们只要更改其中的任何一个,然后其他的也会跟着改变,这就导致 ...

  2. PHP学习之[第02讲]PHP5.4 Apache Mysql 搭配与多站点配置详解

    小编用的是MAC系统,SO安装的是MAMP 知识点: 1.配置多站点:httpd.conf打开httpd-vhosts.conf,并在httpd-vhosts.conf设置多IP及端口指向,最后修改/ ...

  3. php中使用伪静态

    上次简单的说了下php中正则表达式的使用,这一次正则表达式可以派上用场了,学习伪静态需要能够很好的使用正则表达式,那么伪静态和真静态的区别是什么呢,我觉得应该是伪静态可以节约磁盘空间.利于SEO.访问 ...

  4. 【甘道夫】怎样在cdh5.2上执行mahout的itemcf on hadoop

    环境: hadoop-2.5.0-cdh5.2.0 mahout-0.9-cdh5.2.0 步骤: 基本思路是,将mahout下的全部jar包都引入hadoop的classpath就可以,所以改动了$ ...

  5. Java集合类具体解释

    假设您喜欢这些文章,欢迎点击此处订阅本Blog 集合类说明及差别 Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Ma ...

  6. In-Cell、On-Cell和OGS全贴合屏幕技术区别

    昨天刚发布的小米3用的是OGS全贴合屏幕技术,包括魅族MX3也是同样的技术,但是iPhone5是In-Cell屏幕技术,什么才是全贴合?它们之间到底有何区别?哪个好?小编今天就来普及一下全贴合屏幕技术 ...

  7. python使用正則表達式

    python中使用正則表達式 1. 匹配字符 正則表達式中的元字符有 .  ^  $ *   +  ?  { }  [ ]  \  | ( ) 匹配字符用的模式有 \d 匹配随意数字 \D 匹配随意非 ...

  8. 表达式求值 (栈) 用C++实现

    #include <cstdio> #include <cstdlib> #include <cmath> #include <stack> #incl ...

  9. css书写步骤

    CSS整体书写步骤1:CSS RESET 重置2:CSS GLABAL 全局属性3: CSS分模块属性,(先写默认样式和设计图相差最大的部分,先大块布局,后细致调整) <style>/*C ...

  10. Mysql group_concat

    select p.id,p.parent_id,group_concat(distinct(CONCAT("分类名称:",c.name)) order by c.id desc s ...