BZOJ 3505: [Cqoi2014]数三角形 数学
3505: [Cqoi2014]数三角形
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=3505
Description
给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个。下图为4x4的网格上的一个三角形。
注意三角形的三点不能共线。
Input
Output
Sample Input
2 2
Sample Output
HINT
题意
题解:
任意选择三个不在同一条直线上的三个点即是满足题意的点
考虑补集,随意选择3个点,然后删除同一直线,同一斜线的就好了
直线上的比较简单,只用想斜线的就好了
枚举矩形,矩形的长宽分别为i,j,那么这个矩形的对角线就会经过gcd(i,j)-1个点
然后这个图里面可以放(n-i+1)*(m-j+1)个矩形
然后搞一搞就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 510000
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** ll gcd(ll a,ll b)
{
return b==?a:gcd(b,a%b);
}
int main()
{
ll n=read(),m=read();
n++,m++;
ll ans = (n*m)*(n*m-)*(n*m-2LL)/6LL;
ans -= n*(m*(m-1LL)*(m-2LL)/6LL);
ans -= m*(n*(n-1LL)*(n-2LL)/6LL);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
ll tmp = gcd(i,j)+1LL;
if(tmp>2LL)
ans-=(tmp-2LL)*2LL*(n-i*1LL)*(m-j*1LL);
}
}
printf("%lld\n",ans);
}
BZOJ 3505: [Cqoi2014]数三角形 数学的更多相关文章
- 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个的方案减去不合法的, 同一行/列的不合法方案很好求, 对角线的不 ...
- BZOJ 3505: [Cqoi2014]数三角形 [组合计数]
3505: [Cqoi2014]数三角形 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注意三角形的三点不能共线. 1<=m,n<=1000 $n++ m++$ $ans ...
- BZOJ 3505 [Cqoi2014]数三角形
3505: [Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形.注意三角形的三点不能共线. Input ...
- bzoj 3505 [Cqoi2014]数三角形(组合计数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题意] 在n个格子中任选3点构成三角形的方案数. [思路] 任选3点-3点共线 ...
- BZOJ 3505 [Cqoi2014]数三角形(组合数学)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题目大意] 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注 ...
- bzoj 3505 [Cqoi2014]数三角形——排列组合
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505 好题!一定要经常回顾! 那个 一条斜线上的点的个数是其两端点横坐标之差和纵坐标之差的g ...
- bzoj 3505 [Cqoi2014]数三角形 组合
ans=所有的三点排列-共行的-共列的-斜着一条线的 斜着的枚举每个点和原点的gcd,反过来也可以,还能左右,上下挪 #include<cstdio> #include<cstrin ...
随机推荐
- Oracle 课程八之性能优化之Oracle SQL Trace
一. SQL_TRACE 当SQL语句出现性能问题时,我们可以用SQL_TRACE来跟踪SQL的执行情况,通过跟踪,我们可以了解一条SQL或者PL/SQL包的运行情况,SQL_TRACE命令会将SQL ...
- 我们究竟什么时候可以使用Ehcache缓存
一.Ehcache是什么 EhCache是Hibernate的二级缓存技术之一,可以把查询出来的数据存储在内存或者磁盘,节省下次同样查询语句再次查询数据库,大幅减轻数据库压力. 二.Ehcache的使 ...
- SSH超时断开(ClientAliveInterval和ClientAliveCountMax )的使用
有 2个方法 1 配置服务器 打开 /etc/ssh/sshd_config 找到 ClientAliveInterval 参数,如果没有就自己加一行 数值是秒,比如你设置为300,就是5分钟. Cl ...
- 为duilib的MenuDemo增加消息响应,优化代码和显示效果
转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/38253297 第一部分 我在前一段时间研究了怎么制作duilib的菜单, ...
- BufferedReader和BufferedWriter读写文件(转载)
http://375940084.blog.51cto.com/2581965/751040 1.创建Student类存储每个学生信息,属性(学号,姓名,出生日期,得分)2.从c:/test/stud ...
- Python 笔记 : 类和继承
# -*- coding= utf-8 -*- # 文件编码定义的语法规则是: coding[:=]/s*([-/w.]+) # 未指定编码将默认为 : ASCII # 同时要注意物理文件的编码也要 ...
- python中的类型转换
函数 描述 int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) 将x转换到一个浮点数 complex(real [,imag ...
- WinDriver&PCIE
1.安装VS2012 安装VS2012略过,主要用它来做数据传输应用程序的,WINDRIVER提供了一系列API接口,方便了用户,使用户能直接进入用户态的编程,因为内核态的编程它已做好,不需要进行修改 ...
- POJ-1002 解题报告
1.题目描述 http://poj.org/problem?id=1002 2.解题过程 按部就班来解题的话,这个题目很容易写出来,这是我的第一个版本的代码,思路是读入一行电话字符串,均转化为整型 ...
- [Hive-Tutorial] What Is Hive
What Is Hive Hive is a data warehousing infrastructure based on Hadoop. Hadoop provides massive scal ...