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\)开 ...
随机推荐
- java中字符串的比较
compareTo方法是比较两个字符串的词典顺序 也就是在字典中的顺序,比如“abcd”在“acdb”前面 大于返回1,小于返回-1 equals:比较两字符串的内容是否相同. 相同返回1,不同返回 ...
- JS中字符串倒序的两种方法
var reverse = function( str ){ var stack = [];//生成一个栈 for(var len = str.length,i=len;i>=0;i-- ){ ...
- 【深入了解cocos2d-x 3.x】定时器(scheduler)的使用和原理探究(3)
上篇文章分析到了定时器的定义.这篇的重点就是定时器是怎样执行起来的. 1.从main中寻找定时器的回调 讲定时器的执行,就不得不触及到cocos2dx的main函数了,由于定时器是主线程上执行的.并非 ...
- [Angular 2] Using a Value from the Store in a Reducer
RxJS allows you to combine streams in various ways. This lesson shows you how to take a click stream ...
- C语言判断文件是否存在
用函数access,头文件是io.h,原型: int access(const char *filename, int amode); amode参数为0时表示检查文件的 ...
- RESTful Web Services: A Tutorial--reference
As REST has become the default for most Web and mobile apps, it's imperative to have the basics at y ...
- Winform Textbox实现滚动条始终在最下面
在用textbox时,实现一些信息追加时,要使滚动条始终呆在最下面的实现方法. 以textbox1为例,事件TextChanged中执行以下代码即可 private void textBox1_Tex ...
- 逆波兰表达式 java
描述 逆波兰表达式是一种把运算符前置的算术表达式,例如普通的表达式2 + 3的逆波兰表示法为+ 2 3.逆波兰表达式的优点是运算符之间不必有优先级关系, 也不必用括号改变运算次序,例如(2 + 3) ...
- jquery mobile 按钮部件(包含图标的使用)
参考网址:http://api.jquerymobile.com/1.3/button/ 注:按钮的三种写法 <a href="#" class="ui-btn u ...
- jQuery制作go to top按钮
转自:http://www.w3cplus.com/jquery/scrolling-to-the-top-with-jquery 每每看到网友Blog的页面底部或中间有一个按钮回到页面顶部,羡慕死人 ...