【排列组合】bzoj3505 [Cqoi2014]数三角形
http://blog.csdn.net/zhb1997/article/details/38474795
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
int n,m;
ll ans;
int main()
{
// freopen("bzoj3505.in","r",stdin);
scanf("%d%d",&n,&m); ++n; ++m;
ans=(ll)(n*m-2)*(ll)(n*m-1)*(ll)(n*m)/6ll;
ans-=(ll)n*(ll)(m-2)*(ll)(m-1)*(ll)m/6ll;
ans-=(ll)m*(ll)(n-2)*(ll)(n-1)*(ll)n/6ll;
for(int i=1;i<n;++i)
for(int j=1;j<m;++j)
if(__gcd(i,j)>1)
ans-=(ll)(__gcd(i,j)-1)*(ll)(n-i)*(ll)(m-j)*2ll;
cout<<ans<<endl;
return 0;
}
【排列组合】bzoj3505 [Cqoi2014]数三角形的更多相关文章
- [bzoj3505][CQOI2014]数三角形_组合数学
数三角形 bzoj-3505 CQOI-2014 题目大意:给你一个n*m的网格图,问你从中选取三个点,能构成三角形的个数. 注释:$1\le n,m\le 1000$. 想法:本来是想着等中考完了之 ...
- BZOJ3505 [Cqoi2014]数三角形
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- BZOJ3505 CQOI2014数三角形(组合数学)
显然可以用总方案数减掉三点共线的情况.对于三点共线,一个暴力的做法是枚举起点终点,其间整点数量即为横纵坐标差的gcd-1.这样显然会T,注意到起点终点所形成的线段在哪个位置是没有区别的,于是枚举线段算 ...
- [bzoj3505 Cqoi2014] 数三角形 (容斥+数学)
传送门 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. Input 输入一行,包含两个空格分隔的正 ...
- bzoj3505: [Cqoi2014]数三角形 [数论][gcd]
Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. Input 输入一行,包含两个空格分隔的正整数m和 ...
- 2018.09.09 bzoj3505: [Cqoi2014]数三角形(容斥原理+简单计数)
传送门 正难则反. 可以直接把问题转化成求出三点共线的情况数量. 如果同在一排或一列显然可以直接算,关键是如何求出斜着的. 我们知道,对于一个整点矩形. 如果长为x,宽为y,那么这个矩形任意一条对角线 ...
- bzoj3505 [Cqoi2014]数三角形——组合数+容斥
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505 好题啊好题...好像还曾经出现在什么智力测试卷中来着...当时不会现在还是无法自己推出 ...
- 【BZOJ3505】[Cqoi2014]数三角形 组合数
[BZOJ3505][Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. ...
- 【bzoj3505】[Cqoi2014]数三角形
[bzoj3505][Cqoi2014]数三角形 2014年5月15日3,5230 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4×4的网格上的一个三角 ...
随机推荐
- tinyxml学习2
在TinyXML中,根据XML的各种元素来定义了一些类: TiXmlBase:整个TinyXML模型的基类. TiXmlAttribute:对应于XML中的元素的属性. TiXmlNode:对应于DO ...
- SpringMVC整合MongoDB开发 架构搭建
系统环境: 操作系统: windows 7 数 据 库: mongodb2.0.6 驱 动 包: Spring3.1.2 + mongodb2.7.3 + spring-data-mongodb1 ...
- 树莓派make 360wifi2报错
输入make命令后报错 make: *** /lib/modules/3.10.25+/build: No such file or directory. Stop. 系统缺少编译模块所需要的内核头文 ...
- Activity
activity的生命周期: 第一个是:点击按钮切换到另一个activity界面. 第二个是:单击物理返回键的时候,是对当前的activity进行销毁动作. Activity的启动方式:直接启动和匿名 ...
- (Forward) Music Player: From UI Proposal to Code
Some developers have difficult to code when the UI proposal is a bit “sophisticated” or “complex”. M ...
- javaweb学习第一天 debug
debug 断点: f5:step into f6:step over f7:step return drop to frame:跳到当前方法的的第一行 resume:跳到下一个断点 watch:观察 ...
- solr 5.5.1安装并配置中文分词IKAnalyzer
http://www.360doc.com/content/16/0623/17/5131531_570184594.shtml ——————————————————————————————————— ...
- iOS nib file owner
nib文件中的file owner属性,设定后app在运行时加载nib文件的过程中会通过file owner重新建立nib文件中描述的控件与其在file owner中对应的IBOutlet或IBAct ...
- 错误:Unsupported major.minor version 51.0(jdk版本错误)的解决方法
错误:Unsupported major.minor version 51.0(jdk版本错误)的解决方法 java.lang.UnsupportedClassVersionError: org/ap ...
- asp.net GDI+ 使用PathGradienBrush类实现彩色渐变
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...