码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj 3505 [Cqoi2014]数三角形——排列组合

时间:2018-07-03 21:38:06      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:组合   pre   scanf   style   www   line   span   href   tar   

题目: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-1)*(x-2)/6;
}
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=1;i<n;i++)// bh node from 0 to n-1
    for(int j=1;j<m;j++)
      {
    ll num=gcd(i,j)-1;
    if(num>=1)ans-=num*(n-i)*(m-j)*2;
      }
  printf("%lld",ans);
  return 0;
}

 

bzoj 3505 [Cqoi2014]数三角形——排列组合

标签:组合   pre   scanf   style   www   line   span   href   tar   

原文地址:https://www.cnblogs.com/Narh/p/9260588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!