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 ...
随机推荐
- @section Right
布局页 _BaseLayout.cshtml @RenderSection("Right", true) 视图页 Index.cshtml @{ Layout = "~/ ...
- [Everyday Mathematics]20150120
设 $f:\bbR\to\bbR$ 二阶可微, 且 $$\bex f(0)=2,\quad f'(0)=-2,\quad f(1)=1. \eex$$ 试证: $$\bex \exists\ \xi\ ...
- Delphi 操作word 表格
var wordApp, WordDoc, WrdSelection, wrdtable: variant; strAdd: string; wdPar,wdRange:OleVariant; iCo ...
- Core Java 学习笔记——2.基本数据类型&类型转换
数据类型(8种基本类型:int/short/long/byte/float/double/char/boolean) 整型 int 4字节 -2 147 483 648~2 147 483 647 s ...
- oc_转_类的数组的实现和操作
OC的数组对象的基本方法的使用:因为OC的数组中存储的为对象类型,所以我们可以新建一个Person类,通过Person生成对象进行操作. 其中Person.h中的代码为: 01.#import&l ...
- 多级联动导航栏(top导航)
http://www.dynamicdrive.com/style/csslibrary/item/jquery_multi_level_css_menu_2/ This is a multi-lev ...
- 题目1434:今年暑假不AC (项目安排类:结束时间快排,判断开始时间)
题目描述: “今年暑假不AC?”“是的.”“那你干什么呢?”“看世界杯呀,笨蛋!”“@#$%^&*%...”确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视作为 ...
- Windows服务-手把手带你体验
Microsoft Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而 ...
- The solution to Force.Com IDE 29.0 PassWord Problem
我最近使用Force.com IDE 时,经常提示密码错误.从Google 中终于发现一个解决方法,分享给大家,以供大家参考. 在Force.com IDE 29.0中,IDE 存储我们开发Org ...
- <Araxis Merge>Windows平台下的Merge概览
它是什么 Merge是一个来自Araxis的可视化文件比较/合并及文件夹同步的应用程序. 用户界面使用英语.德语.日语.法语.国际西班牙语.汉语(繁体和简体)进行本地化了. 优势 对于软件工程师和网站 ...