Mission



对于100%的数据1<=m,n<=1000

Solution

鬼题,ans=C3(n∗m)−Ans,其中Ans表示三点共线的数目;

枚举最长边的向量(x,y),容易算出贡献及个数。

Code

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
const char* fin="aP1.in";
const char* fout="aP1.out";
const ll inf=0x7fffffff;
const ll maxn=1007;
ll n,m,i,j,k,ans;
ll c[maxn*maxn][4];
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
scanf("%lld%lld",&n,&m);n++,m++;
for (i=0;i<maxn*maxn;i++){
c[i][0]=1;
for (j=1;j<=min(i,3LL);j++) c[i][j]=c[i-1][j-1]+c[i-1][j];
}
ans=c[n*m][3];
for (i=0;i<n;i++)
for (j=0;j<m;j++){
if (i==0 && j==0) continue;
else if (i==0) k=j-1;
else if (j==0) k=i-1;
else k=(gcd(i,j)-1)*2;
ans-=(n-i)*(m-j)*k;
}
printf("%lld",ans);
return 0;
}

Warning

想到了正难则反,

但是没有想到枚举最长边。

想到的却是枚举较短的边。

枚举的东西尽量大点,好计算。

【JZOJ3598】【CQOI2014】数三角形的更多相关文章

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

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

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

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

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

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

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

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

  5. 3505: [Cqoi2014]数三角形

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1324  Solved: 807[Submit][Statu ...

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

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

  7. [CQOI2014]数三角形

    [CQOI2014]数三角形 给定\(n\times m\)的网格,求三个点在其格点上的三角形个数,1<=m,n<=1000. 解 法一:直接 显然为组合计数问题,关键在于划分问题,注意到 ...

  8. bzoj3505 / P3166 [CQOI2014]数三角形

    P3166 [CQOI2014]数三角形 前置知识:某两个点$(x_{1},,y_{1}),(x_{2},y_{2})\quad (x_{1}<x_{2},y_{1}<y_{2})$所连成 ...

  9. BZOJ 3505 [Cqoi2014]数三角形

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

  10. 【BZOJ3505】[Cqoi2014]数三角形 组合数

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

随机推荐

  1. DataLossError (see above for traceback): file is too short to be an sstable [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_F

    DataLossError (see above for traceback): file is too short to be an sstable [[Node: save/RestoreV2 = ...

  2. LeetCode404Sum of Left Leaves左叶子之和

    计算给定二叉树的所有左叶子之和. 示例: 3 / \ 9    20 / \ 15   7 在这个二叉树中,有两个左叶子,分别是 9 和 15,所以返回 24 class Solution { pub ...

  3. 1、mysql安装教程

    1.https://www.runoob.com/mysql/mysql-install.html   参考安装链接 Windows 上安装 MySQL Windows 上安装 MySQL 相对来说会 ...

  4. rabbitmq类

    1.accept.php消费者代码需要在命令行执行 2.'username'=>'asdf','password'=>'123456' 改成自己的帐号和密码 RabbitMQCommand ...

  5. Kubernetes集群环境准备

    目录 二.准备工作 ​ 主机名 IP地址(NAT) 描述 linux-node1.example.com eth0:192.168.56.11 Kubernets Master节点/Etcd节点 li ...

  6. 19-10-23-K-Aft

    没改完题就过来沽博客是不是有点不好…… ZJ一下: 好好好题. T1数组大小…… $$10^7 \rightarrow 60$$ 事实上…… $$7 \times 10^7 \rightarrow 0 ...

  7. 深入浅出 Java Concurrency (10): 锁机制 part 5 闭锁 (CountDownLatch)[转]

    此小节介绍几个与锁有关的有用工具. 闭锁(Latch) 闭锁(Latch):一种同步方法,可以延迟线程的进度直到线程到达某个终点状态.通俗的讲就是,一个闭锁相当于一扇大门,在大门打开之前所有线程都被阻 ...

  8. 微信小程序上传图片(附后端代码)

    几乎每个程序都需要用到图片. 在小程序中我们可以通过image组件显示图片. 当然小程序也是可以上传图片的,微信小程序文档也写的很清楚. 上传图片 首先选择图片 通过wx.chooseImage(OB ...

  9. python进阶_浅谈面向对象进阶

    python进阶_浅谈面向对象进阶 学了面向对象三大特性继承,多态,封装.今天我们看看面向对象的一些进阶内容,反射和一些类的内置函数. 一.isinstance和issubclass  class F ...

  10. VS中warning MSB8004和error MSB4018解决方案

    问题如下: warning MSB8004: Output Directory does not end with a trailing slash.  This build instance wil ...