题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505

好题!一定要经常回顾!

那个 一条斜线上的点的个数是其两端点横坐标之差和纵坐标之差的gcd-1 真是很妙。

https://blog.csdn.net/u012288458/article/details/48624859

https://www.cnblogs.com/Var123/p/5377616.html

然而还可以递推?https://www.cnblogs.com/liu-runda/p/5993244.html 反正没管……

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int n,m;
ll ans;
ll C(int x)
{
return (ll)x*(x-)*(x-)/;
}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main()
{
scanf("%d%d",&n,&m);n++;m++;
ans=C(n*m)-n*C(m)-m*C(n);
for(int i=;i<n;i++)// bh node from 0 to n-1
for(int j=;j<m;j++)
{
ll num=gcd(i,j)-;
if(num>=)ans-=num*(n-i)*(m-j)*;
}
printf("%lld",ans);
return ;
}

bzoj 3505 [Cqoi2014]数三角形——排列组合的更多相关文章

  1. bzoj 3505 [Cqoi2014]数三角形(组合计数)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题意] 在n个格子中任选3点构成三角形的方案数. [思路] 任选3点-3点共线 ...

  2. BZOJ 3505: [Cqoi2014]数三角形 [组合计数]

    3505: [Cqoi2014]数三角形 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注意三角形的三点不能共线. 1<=m,n<=1000 $n++ m++$ $ans ...

  3. BZOJ 3505 [Cqoi2014]数三角形

    3505: [Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形.注意三角形的三点不能共线. Input ...

  4. BZOJ 3505: [Cqoi2014]数三角形 数学

    3505: [Cqoi2014]数三角形 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...

  5. Bzoj 3505: [Cqoi2014]数三角形 数论

    3505: [Cqoi2014]数三角形 Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits   Description

  6. bzoj 3505: [Cqoi2014]数三角形 组合数学

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 478  Solved: 293[Submit][Status ...

  7. BZOJ 3505: [Cqoi2014]数三角形( 组合数 )

    先n++, m++ 显然答案就是C(3, n*m) - m*C(3, n) - n*C(3, m) - cnt. 表示在全部点中选出3个的方案减去不合法的, 同一行/列的不合法方案很好求, 对角线的不 ...

  8. bzoj 3505 [Cqoi2014]数三角形 组合

    ans=所有的三点排列-共行的-共列的-斜着一条线的 斜着的枚举每个点和原点的gcd,反过来也可以,还能左右,上下挪 #include<cstdio> #include<cstrin ...

  9. BZOJ 3505 [Cqoi2014]数三角形(组合数学)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题目大意] 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注 ...

随机推荐

  1. samtools的基本用法

    1.sam,bam的格式转换: $samtools view -sb file.sam >file.bam $samtools view -sb file.sam -o file.bam #sa ...

  2. ==、equals与hashCode

    ==  首先,得说明java数据类型分为基本数据类型和引用数据类型, 基本数据类型有8种: 浮点型:float(4 byte), double(8 byte) 整型:byte(1 byte), sho ...

  3. css transform常用变化解析

    本文旨在对常用变化做最直观的简析 translate 移动 translateX() X轴正方向移动(单位可为px,也可为%,为%时以自身为参照物) translateY() Y轴反方向移动 tran ...

  4. POJ 1144 无向图求割点

     学长写的: #include<cstdio>#include<cstdlib>#include<cmath>#include<iostream>#in ...

  5. 深入Spring:自定义注解加载和使用

    前言 在工作中经常使用Spring的相关框架,免不了去看一下Spring的实现方法,了解一下Spring内部的处理逻辑.特别是开发Web应用时,我们会频繁的定义@Controller,@Service ...

  6. mysql中两表更新时产生的奇葩问题,产生死锁!

    如下一个两表更新语句 UPDATE hzxm201610 a,xmhzylb1201610 b SET a.gk07_1_6=b.gk04_11,a.gk07_2_6=b.f06_1,a.gk07_3 ...

  7. spring+springmvc+mybatis(ssm)

    1.jdbc.properties jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/jk ...

  8. boot小知识

    lg 大, md 中等, sm 小, xs 极小. 可以单独用,也可以混合用,不同的屏幕用不同的比例. push ,pull 推拉.这个不实用. row里面可以嵌套实用row. 挤不下的时候,就会自动 ...

  9. 我的博客搬家到https://www.w2le.com/了

    大家以后想看我的博文的请到这里哦,欢迎大家访问https://www.w2le.com/

  10. Windows 10 Certified with Oracle E-Business Suite

    Microsoft Windows 10 (32-bit and 64-bit) is certified as a desktop client operating system for end-u ...