【CQOI2014】数三角形
题面
题解
考虑使用总数减去不合法的数量
首先将\(n, m\)都加上\(1\),将网格变成坐标系
总数即为\(\large\binom{n\times m}{3}\)
不合法的有三种情况:
三个点在同一行上。每一行有\(\binom{m}{3}\)种不合法的情况,有\(n\)行,总数\(n\cdot\binom m3\)
三个点在同一列上。每一列有\(\binom n3\)种不合法的情况,有\(m\)行,总数\(m\cdot\binom n3\)
三个点在同一条斜线上
如果斜率为正,那么将一个点移动到原点,然后枚举另外一个点,这样的直线有
\((n - i)(m - j)\)条
然后斜率可能为负,\(\times 2\)即可
于是总数就是\(2\sum\limits_{i=1}^{n-1}\sum\limits_{j=1}^{m-1}(\gcd(i,j)-1)(n-i)(m-j)\)
于是答案为
\]
代码
结论题的代码就是好打
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
inline int read()
{
int data = 0, w = 1; char ch = getchar();
while(ch != '-' && (!isdigit(ch))) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
}
inline long long C(int x) { return 1ll * x * (x - 1) * (x - 2) / 6; }
long long ans; int n, m;
int main()
{
n = read() + 1, m = read() + 1;
ans = C(n * m) - n * C(m) - m * C(n);
for(RG int i = 1; i < n; i++)
for(RG int j = 1; j < m; j++)
ans -= 2ll * (std::__gcd(i, j) - 1) * (n - i) * (m - j);
printf("%lld\n", ans);
return 0;
}
【CQOI2014】数三角形的更多相关文章
- BZOJ 3505: [Cqoi2014]数三角形 数学
3505: [Cqoi2014]数三角形 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- Bzoj 3505: [Cqoi2014]数三角形 数论
3505: [Cqoi2014]数三角形 Time Limits: 1000 ms Memory Limits: 524288 KB Detailed Limits Description
- bzoj 3505: [Cqoi2014]数三角形 组合数学
3505: [Cqoi2014]数三角形 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 478 Solved: 293[Submit][Status ...
- BZOJ 3505: [Cqoi2014]数三角形( 组合数 )
先n++, m++ 显然答案就是C(3, n*m) - m*C(3, n) - n*C(3, m) - cnt. 表示在全部点中选出3个的方案减去不合法的, 同一行/列的不合法方案很好求, 对角线的不 ...
- 3505: [Cqoi2014]数三角形
3505: [Cqoi2014]数三角形 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1324 Solved: 807[Submit][Statu ...
- BZOJ 3505: [Cqoi2014]数三角形 [组合计数]
3505: [Cqoi2014]数三角形 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注意三角形的三点不能共线. 1<=m,n<=1000 $n++ m++$ $ans ...
- [CQOI2014]数三角形
[CQOI2014]数三角形 给定\(n\times m\)的网格,求三个点在其格点上的三角形个数,1<=m,n<=1000. 解 法一:直接 显然为组合计数问题,关键在于划分问题,注意到 ...
- bzoj3505 / P3166 [CQOI2014]数三角形
P3166 [CQOI2014]数三角形 前置知识:某两个点$(x_{1},,y_{1}),(x_{2},y_{2})\quad (x_{1}<x_{2},y_{1}<y_{2})$所连成 ...
- BZOJ 3505 [Cqoi2014]数三角形
3505: [Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形.注意三角形的三点不能共线. Input ...
- 【BZOJ3505】[Cqoi2014]数三角形 组合数
[BZOJ3505][Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. ...
随机推荐
- 【Kettle】2、文件夹与界面介绍
1.文件夹介绍 下载Kettle6.1解压后出现下图相关文件夹以及文件夹介绍说明: Lib:存放Kettle的核心(core)jar包.工作引擎(engine)jar包.数据库(DB) jar包.图形 ...
- C# 调用WebService服务
方 法 一 : 选择项目,右键添加服务引用,输入服务地址,如图: 点击确定跳转到如下界面: 调用 接口: ServiceReference1.ImportDataServiceClient sr = ...
- Jquery组织Form表单提交之Form submission canceled because the form is not connected
有时候导出Excel时需要根据某些条件筛选数据,然后将数据通过NPOI生成Excel并导出.组织数据时可以通过放到一个表单中,某些场景是使用脚本(如:jquery)组织一个form(通过字符串拼接), ...
- 关于springMVC的一些常用注解
①:@RequestMapping("/helloworld").@RequestMapping(value="/emp", method=RequestMet ...
- 获取系统屏幕尺寸参数的类WxHxD
获取系统屏幕尺寸参数的类WxHxD 源码: // // WxHxD.h // PM2.5 // // Created by YouXianMing on 14/10/29. // Copyright ...
- web.config设置之system.webServer 详细介绍,为网站设置默认文档
如何:为 IIS 7.0 配置 <system.webServer> 节2008-06-14 22:26http://technet.microsoft.com/zh-cn/sysinte ...
- Bootstrap后台管理框架
B-JUI http://www.xknaan.com/ B-JUI 前端框架,基于Bootstrap的Jquery UI框架,核心思想脱胎于DWZ(j-ui). BJUI_SSM_DEMO 基于 ...
- 【原创】uwsgi中多进程+多线程原因以及串行化accept() - thunder_lock说明
如有不对,请详细指正. 最近再研究uwsgi如何部署python app,看uwsgi的文档,里面有太多的参数,但每个参数的解释太苍白,作为菜鸟的我实在是不懂.想搞清楚uwsgi的工作原因以及里面的一 ...
- haproxy 启动错误
在haproxy启动时会报错 ALERT] / () : Starting proxy short_message: cannot bind socket 问题1,如果bind的是vip,则需要内核添 ...
- Spring Security with Boot
1.spring安全 boot中的应用文档https://docs.spring.io/spring-security/site/docs/current/guides/html5//hellowor ...