题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1296

题意:给出一个a*b的网格,在网格上取不共线的三点构成三角形,求三角形总数。
分析:就是一一道简单的组合数计算题目,设总结点数为n,则取三个节点的个数为C(n,3),

然后减去横向、竖向、斜向的三点共线的个数即可,斜线三点共线等价于所枚举的矩形的长宽成倍数关系,即gcd不为1

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
int main(){
ll a, b;
int cas = ;
while(scanf("%lld%lld", &a, &b)!=EOF && (a||b)){
ll n = (a+)*(b+);
ll sum1 = n*(n-)*(n-)/; //C(n,3)
ll sum2 = (b+)*(a+)*a*(a-)/ + (a+)*(b+)*b*(b-)/; //横向或竖向三点共线的个数
ll sum3 = ; //斜线上三点共线的个数的一半
int i, j;
for(i=; i<=a; i++)
for(j=; j<=b; j++)
sum3 += (gcd(i,j)-) * (a-i+) * (b-j+);
ll ans = sum1 - *sum3 - sum2;
printf("Case %d: %lld\n", cas++, ans);
}
return ;
}

UVALive 3295 Counting Triangles的更多相关文章

  1. hdu 1396 Counting Triangles(递推)

    Counting Triangles Problem Description Given an equilateral triangle with n thelength of its side, p ...

  2. Counting Triangles(hd1396)

    Counting Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. UVA 12075 - Counting Triangles(容斥原理计数)

    题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...

  4. 1307 - Counting Triangles

    1307 - Counting Triangles    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  5. LA 3295 (计数 容斥原理) Counting Triangles

    如果用容斥原理递推的办法,这道题确实和LA 3720 Highway很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单: ...

  6. UVALive 5058 Counting BST 数学

    B - Counting BST Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  7. UVALive 5058 Counting BST --组合数

    题意:排序二叉树按照数插入的顺序不同会出现不同的结构,现在要在1~m选n个数,使按顺序插入形成的结构与给出的结构相同,有多少种选法. 解法:先将给出的结构插入,构造出一棵排序二叉树,再dfs统计,首先 ...

  8. UVaLive 6602 Counting Lattice Squares (找规律)

    题意:给定一个n*m的矩阵,问你里面有几面积为奇数的正方形. 析:首先能知道的是,大的矩阵是包括小的矩阵的,而且面积为奇数,我们只要考虑恰好在边界上的正方形即可,画几个看看就知道了,如果是3*3的有3 ...

  9. UVALive 6602 Counting Lattice Squares

    给定一个n*m的网格,求面积为奇数的正方形有多少个. 首先是n*m个面积为1的,然后剩下的要么是边长为奇数,要么被这样一个奇数边长所包围. 原因如下: 对于一个边长不平行于坐标抽的正方形,其边长一定是 ...

随机推荐

  1. centos 安装 pcre

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/luozhonghua2014/article/details/37054235 #rpm -qa | ...

  2. wxPython:文本对话框TextEntryDialog

    wxTextEntryDialog(wxWindow* parent, const wxString& message, const wxString& caption = " ...

  3. python的__getitem__

    #这个方法返回与指定键相关的值.对序列来说,键应该是0~n-1的整数,其中n为序列的长度.对映射来说,键可以是任何类型. class Test(object): def __init__(self): ...

  4. python的目录

    1.python的当前目录 d = os.path.dirname(__file__) #和文件强依赖,即使该语句被别的文件调用,d也不会改变或者d = os.getcwd() #当该语句被别的文件调 ...

  5. function module 之间调用

    1: 在一个function group 中定义一个function module 2:在另外一个module中调用该module "调用其它function 要用 单引号 引着. 一个mo ...

  6. es7新特性 includes用法

    返回数组是否包含某个元素 var array1 = [1, 2, 3]; console.log(array1.includes(2)); // expected output: true

  7. emq知识点

    1  配置用户名 默认是可以匿名登录(与mosquitto相同) ## Allow Anonymous authentication mqtt.allow_anonymous = true etc/p ...

  8. jenkins windows slave 报错ERROR: Error cloning remote repo 'origin'

    在slave上是git clone ssh是可以成功的,但是jenkins调用slave节点就报如下错误: ERROR: Error cloning remote repo 'origin' huds ...

  9. Solutions_issues in pip

    pip fails ssl verification Solution: $ python -m pip <command> --trusted-host files.pythonhost ...

  10. .net core 路由处理请求流程图