【BZOJ3505】【数论】数三角形 题解
来源:互联网 发布:移动宽带网络参数设置 编辑:程序博客网 时间:2024/06/05 20:24
数三角形
给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个。下图为4x4的网格上的一个三角形。
注意三角形的三点不能共线。
Input
输入一行,包含两个空格分隔的正整数m和n。
Output
输出一个正整数,为所求三角形数量。
Sample Input
2 2
Sample Output
76
数据范围
1<=m,n<=1000
找规律,之后组合数,然后排除不合法的。
#include <iostream>#include <cstdio>#define LL long long#ifdef WIN32#define AUTO "%I64d"#else#define AUTO "%lld"#endif using namespace std;int n,m;LL c[1005005][4];LL ans,tmp;inline int gcd(int a, int b) { return !b ? a : gcd(b, a%b); }void getc() { c[0][0] = 1; for(int i = 1; i <= n*m; i++) { c[i][0] = 1; for(int j = 1; j <= 3; j++) c[i][j] = c[i-1][j-1]+c[i-1][j]; }}void solve() { ans = c[n*m][3]-n*c[m][3]-m*c[n][3]; for(int i = 1; i < n; i++) for(int j = 1; j < m; j++) { tmp = gcd(i, j)+1; if(tmp > 2) ans -= (tmp-2)*2*(n-i)*(m-j); }}int main() { scanf("%d%d",&n,&m); n++; m++; getc(); solve(); printf(AUTO,ans); return 0;}
阅读全文
0 0
- BZOJ3505 数三角形 题解 【数论】
- 【BZOJ3505】【数论】数三角形 题解
- bzoj3505 [Cqoi2014]数三角形 题解
- 【组合】BZOJ3505(Cqoi2014)[数三角形]题解
- [Bzoj3505][Cqoi2014]数三角形
- bzoj3505 [Cqoi2014]数三角形
- bzoj3505: [Cqoi2014]数三角形
- bzoj3505 [Cqoi2014]数三角形
- 【CQOI2014】【BZOJ3505】数三角形
- bzoj3505【CQOI2014】数三角形
- bzoj3505: [Cqoi2014]数三角形
- 【bzoj3505】[Cqoi2014]数三角形
- BZOJ3505[数三角形]
- bzoj3505 [Cqoi2014]数三角形
- bzoj3505 [Cqoi2014]数三角形
- BZOJ3505 [Cqoi2014]数三角形
- 【bzoj3505】 CQOI2014数三角形 数学
- BZOJ3505 [Cqoi2014]数三角形 数学
- Shell封装linux命令--代码同步
- POJ 3159 Candies 差分入门
- TQ2440开发板学习纪实(4)--- 初始化片外RAM,让程序有更大内存空间
- Centos6 修改主机名
- struts2自定义类型转换
- 【BZOJ3505】【数论】数三角形 题解
- 【过了】系统分析师考试心得
- “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛-专题
- 单链表的简单实现
- MySQL 5.7解压版安装、卸载及乱码问题解决
- VLC学习(1) Linux 下编译 VLC for Android
- STM32学习笔记一一TFTLCD 显示
- c3p0是什么
- 剑指Offer_面试题03_二维数组中的查找