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. hadoop settings

    ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys expor ...

  2. 深度残差网络——ResNet学习笔记

    深度残差网络—ResNet总结 写于:2019.03.15—大连理工大学 论文名称:Deep Residual Learning for Image Recognition 作者:微软亚洲研究院的何凯 ...

  3. Unity 用代码设置UGUI的渲染层级

    用代码设置UGUI渲染无非和三个API有关: 1.SetAsFirstSibling(); 2.SetAsLastSibling(); 3.SetSiblingIndex(n) SetAsFirstS ...

  4. Lua程序设计之数值

    (摘自Lua程序设计) 数值常量 从Lua5.3版本开始Lua语言为数值格式提供了两种选择:被称为integer的64位整形和被称为float的双精度浮点类型(注意,"float" ...

  5. GetCommandLine CmdLineToArgvW

    说明:LPTSTR GetCommandLine(VOID); LPWSTR * CommandLineToArgvW(                                        ...

  6. P1249 最大乘积

    打暴力找规律,都是连续自然数去掉一个 n=int(input()) a=[] cnt=0 i=2 tot=0 ans=1 while tot<=n: tot+=i cnt+=1 a.append ...

  7. 【踩坑】nextSibling 和nextElementSibling的区别

    DOM 使用nextSibling属性返回指定节点之后的下一个兄弟节点,(即:相同节点树层中的下一个节点). nextSibling属性与nextElementSibling属性的差别: nextSi ...

  8. android 开发环境问题

    一.console出现The connection to adb is down, and a severe error has occured. .先把eclipse关闭. .在管理器转到你的and ...

  9. IO流18 --- RandomAccessFile实现数据的读写操作 --- 技术搬运工(尚硅谷)

    RandomAccessFile实例化时,需要设置读写模式 示例:复制文件 @Test public void test16() throws IOException { RandomAccessFi ...

  10. ElasticSearch基本操作(安装,索引的创建和删除,映射)

    ElasticSearch基于Lucene的搜索服务器,支持分布式,提供REST接口,可用于云计算,可以实现实时搜索,开源免费.这时很官方的一句话,在使用之前,我们简单的介绍一下安装过程.在官网下载之 ...