zoj 3647 Gao the Grid
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的更多相关文章
- ZOJ 3647 Gao the Grid dp,思路,格中取同一行的三点,经典 难度:3
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 三角形的总数=格子中任取3个点的组合数-同一横行任取3个点数目-同一纵行 ...
- 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 ...
- 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 ...
- 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 ...
- zoj 3672 Gao The Sequence
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意 ...
- zoj 3647 智商题
此题就是求格点中三角形的个数. 就是找出三点不共线的个数. n*m的矩形中有(n+1)*(m+1)个格点. 选出三个点的总个数为:C((n+1)*(m+1),3). 减掉共线的情况就是答案了. 首先是 ...
- 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 ...
- ZOJ 3780 - Paint the Grid Again - [模拟][第11届浙江省赛E题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Time Limit: 2 Seconds Me ...
- ZOJ 3408 Gao
ZOJ题目页面传送门 给定一个有向图\(G=(V,E),n=|V|,m=|E|\)(可能有重边和自环,节点从\(0\)开始编号),以及\(q\)组询问,对于每组询问你需要回答有多少条从节点\(0\)开 ...
随机推荐
- banana pro 板子
http://www.lemaker.org/cn/article-23-1.html
- windows 消息机制的学习
概述 链接1:http://www.cppblog.com/suiaiguo/archive/2009/07/18/90412.html 链接2:http://www.cnblogs.com/find ...
- Eclipse自动插件依赖的一种配置解决方式
Eclipse的插件具有以下特点: (1)每一个插件有自己独立的classloader (2)插件资源的交互通过MENIFEST.MF中"Export-Package, Require-Bu ...
- MySQL(13):Select-order by
1. 按照字段值进行排序: 语法: order by 字段 升序|降序(asc|desc) 允许多字段排序,指的是,先按照第一个字段排序,如果说,不能区分,才使用第二个字段,以此类推. ...
- JVM内存回收对象及引用分析
自动垃圾回收是Java相较于C++的一个重要的特点,想了解JVM的垃圾回收机制,首先我们要知道垃圾回收是回收什么地方的垃圾,我在我的上一篇博客<JVM内存区域划分>里面有写到JVM里面的内 ...
- POJ 3865 - Database 字符串hash
[题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每 ...
- .Net程序员 Solr-5.3之旅 (三)Solr 从MSSQ导入索引数据
阅读目录 引言 准备工作 data-config.xml schema.xml 导入数据 结尾 附件下载 引言 Other men live to eat, while I eat to live.- ...
- DIV布局之道一:DIV块的水平并排、垂直并排
DIV布局网页元素的方式主要有三种:平铺(并排).嵌套.覆盖(遮挡).本文先讲解平铺(并排)方式. 1.垂直平铺(垂直排列) 请看如下代码 CSS部分: CSS Code复制内容到剪贴板 .lay1{ ...
- mouseover,mouseout和mouseenter,mouseleave
mouseover和mouseout 鼠标指针进入或者离开被选元素或其子元素,都会触发相应事件. 非IE浏览器支持该事件. mouseenter和mouseleave 只有在鼠标指针进入或者离开被选元 ...
- Css Div半透明
用CSS控制外层DIV不透明,而内层DIV透明,这样实现的效果是意想不到的,还不错吧,其实代码也是很简单的,也很好理解,主要是用了CSS的滤镜. <html xmlns="http:/ ...