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\)开 ...
随机推荐
- localStorage存储JSON对象的小方法
有时候,我们需要将数据存储到sessionStorage和localStorage中,这样做的好处有: 1 缓存数据 2 减少对内存的占用 但是,storage只能存储字符串的数据,对于JS中常用的数 ...
- fork安全的gettid高效实现
进程有id,可以通过getpid()获得,线程也有id,但是glibc没有提供封装.需要自己发出系统调用.在关键路径,系统调用还是对性能有影响的.因此我们可以想到类似glibc对getpid做的cac ...
- C#Linq的使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- GridView and DropDownList
<form id="form1" runat="server"> <div> <asp:GridView runat=" ...
- .Net使用SSH.NET通过SSH访问Linux主机
使用了SSH.NET库,添加引用dll至项目,以下代码显示了点击按钮后SSH链接Linux主机执行命令并返回命令执行结果 protected void btnExcute_Click(object s ...
- [php基础]PHP Form表单验证:PHP form validator使用说明
在PHP网站开发建设中,用户注册.留言是必不可少的功能,用户提交的信息数据都是通过Form表单提交,为了保证数据的完整性.安全性,PHP Form表单验证是过滤数据的首要环节,PHP对表单提交数据的验 ...
- Lesson 4: Know Your Tools
Lesson 4: Know Your Tools "差劲的人
- c - 十六进制 转 十进制
考虑到举一反三,这里顺便上完整代码,顺便可以考虑实现R进制和十进制的转换. 完整代码: #include <stdio.h> #include <math.h> double ...
- ESXi控制台TSM:弥补vSphere Client不足
当vSphere Client不能完成某些任务时,主机的ESXi控制台及其技术支持模式(TSM)可能能派上用场. ESXi控制台允许管理员执行不能通过vSphere Client进行配置的管理任务,比 ...
- javascript代码放置位置对程序的影响
在编写html文档时,javascript可以放置的位置有两个地方<head>或者<body>,但是放置的地方,会对 JavaScript 代码的正常执行会有一定影响.由于 H ...