bzoj 3505 [Cqoi2014]数三角形(组合计数)
【题目链接】
http://www.lydsy.com/JudgeOnline/problem.php?id=3505
【题意】
在n个格子中任选3点构成三角形的方案数。
【思路】
任选3点-3点共线的情况。
【代码】
#include<cstdio>
#include<iostream>
using namespace std; typedef long long ll; ll C[][]; void get_pre(int n)
{
C[][]=;
for(int i=;i<=n;i++) {
C[i][]=;
for(int j=;j<=;j++)
C[i][j]=C[i-][j]+C[i-][j-];
}
}
int gcd(int i,int j)
{
return j==?i:gcd(j,i%j);
}
int n,m; int main()
{
scanf("%d%d",&n,&m);
n++,m++;
if(n>m) swap(n,m);
get_pre(n*m);
ll ans=C[n*m][],tmp=;
ans-=n*C[m][]+m*C[n][];
for(int i=;i<n;i++) for(int j=;j<m;j++) {
int x=gcd(i,j)+;
if(x>)
ans-=(x-)**(n-i)*(m-j);
}
printf("%lld\n",ans);
return ;
}
bzoj 3505 [Cqoi2014]数三角形(组合计数)的更多相关文章
- BZOJ 3505: [Cqoi2014]数三角形 [组合计数]
3505: [Cqoi2014]数三角形 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注意三角形的三点不能共线. 1<=m,n<=1000 $n++ m++$ $ans ...
- bzoj 3505 [Cqoi2014]数三角形 组合
ans=所有的三点排列-共行的-共列的-斜着一条线的 斜着的枚举每个点和原点的gcd,反过来也可以,还能左右,上下挪 #include<cstdio> #include<cstrin ...
- BZOJ 3505 [Cqoi2014]数三角形
3505: [Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形.注意三角形的三点不能共线. Input ...
- BZOJ 3505: [Cqoi2014]数三角形 数学
3505: [Cqoi2014]数三角形 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- Bzoj 3505: [Cqoi2014]数三角形 数论
3505: [Cqoi2014]数三角形 Time Limits: 1000 ms Memory Limits: 524288 KB Detailed Limits Description
- bzoj 3505: [Cqoi2014]数三角形 组合数学
3505: [Cqoi2014]数三角形 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 478 Solved: 293[Submit][Status ...
- BZOJ 3505: [Cqoi2014]数三角形( 组合数 )
先n++, m++ 显然答案就是C(3, n*m) - m*C(3, n) - n*C(3, m) - cnt. 表示在全部点中选出3个的方案减去不合法的, 同一行/列的不合法方案很好求, 对角线的不 ...
- bzoj 3505 [Cqoi2014]数三角形——排列组合
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505 好题!一定要经常回顾! 那个 一条斜线上的点的个数是其两端点横坐标之差和纵坐标之差的g ...
- BZOJ 3505 [Cqoi2014]数三角形(组合数学)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题目大意] 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注 ...
随机推荐
- 在PowerDesigner中设计概念模型
原文:在PowerDesigner中设计概念模型 在概念模型中主要有以下几个操作和设置的对象:实体(Entity).实体属性 (Attribute).实体标识(Identifiers).关系(Rela ...
- 231. Power of Two
题目: Given an integer, write a function to determine if it is a power of two. 链接: http://leetcode.com ...
- openfire开发
openfire github地址:https://github.com/igniterealtime/Openfire 1.下载源代码:http://www.igniterealtime.org/d ...
- JUnit单元测试--小试牛刀
单元测试更多的是在开发阶段完成,开发人员每写一个函数的时候都会写相应的单元测试.对于java代码,普遍使用的是jUnit,根据jUnit可以自己相应的开发一套自动化测试框架.这个的前提是要学会juni ...
- PHP5.4连接sqlserver
1.下载微软的php连接驱动:SQLSRV30.EXE(5.4对应,后面的native client要用2012)/SQLSRV20.EXE(5.3对应,native client要用2008)/SQ ...
- linux中proc文件系统 -- ldd3读书笔记
1./proc 文件系统概述 /proc 文件系统是由软件创建,被内核用来向外界报告信息的一个文件系统./proc 下面的每一个文件都和一个内核函数相关联,当文件的被读取时,与之对应的内核函数用于产生 ...
- Android相对布局(RelativeLayout)
Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...
- 实现微信好友列表的php代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ScaleGestureDetector缩放view
public class ScaleGesture implements OnScaleGestureListener { private float beforeFactor; private fl ...
- struts.custom.i18n.resources 如何配置多个资源文件?
struts.custom.i18n.resources = resources1,resources2,resources3 配置properties文件