hdu 5116 计数
题目大意:给你n个点, n个点的坐标都在200以内,让你统计不相交的两个L形的种数,且L形的两条边长的gcd = 1。
思路:用二维树状数组维护点的信息,然后划分区块进行统计,题解是用总的减去相交的,不需要用到二维树状数组。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = + ;
const int M = 1e4 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +;
const double eps=1e-;
const double pi=acos(-); int n, m, up[N][N], rt[N][N];
LL cnt[N][N], num[N][N];
bool Map[N][N]; struct BIT {
LL a[N][N];
void modify(int x, int y, LL v) {
for(int i = x; i < N; i += i & -i)
for(int j = y; j < N; j += j & -j)
a[i][j] += v;
} LL sum(int x, int y) {
LL ans = ;
for(int i = x; i; i -= i & -i)
for(int j = y; j; j -= j & -j)
ans += a[i][j];
return ans;
} void init() {
memset(a, , sizeof(a));
}
}bit1, bit2; void init() {
for(int i = ; i < N; i++) {
for(int j = ; j < N; j++) {
cnt[i][j] = cnt[i][j - ] + (__gcd(i, j) == );
}
} for(int i = ; i < N; i++) {
for(int j = ; j < N; j++) {
for(int k = ; k <= i; k++) {
num[i][j] += cnt[k][j];
}
}
}
} int main() {
init();
int T; scanf("%d", &T);
for(int cas = ; cas <= T; cas++) {
bit1.init(); bit2.init();
memset(rt, , sizeof(rt));
memset(up, , sizeof(up));
memset(Map, , sizeof(Map)); scanf("%d", &n);
for(int i = ; i <= n; i++) {
int x, y; scanf("%d%d", &x, &y);
Map[x][y] = true;
} for(int i = ; i >= ; i--) {
for(int j = ; j >= ; j--) {
if(Map[i][j]) {
up[i][j] = up[i + ][j] + ;
rt[i][j] = rt[i][j + ] + ;
}
}
} LL ans = ; for(int i = ; i >= ; i--) {
for(int j = ; j <= ; j++) {
if(!Map[i][j] || up[i][j] <= || rt[i][j] <= ) continue;
ans += num[up[i][j] - ][rt[i][j] - ] * (bit2.sum(, ) - bit2.sum(i + up[i][j] - , j)); int q = i + up[i][j] - ;
for(int k = i + ; k <= && k <= q; k++) {
ans += cnt[k - i][rt[i][j] - ] * (bit2.sum(q, j) - bit2.sum(k, j));
ans += cnt[k - i][rt[i][j] - ] * (bit1.sum(k, j - ));
} bit2.modify(i, j, num[up[i][j] - ][rt[i][j] - ]);
for(int k = j + ; k <= && k < j + rt[i][j]; k++) {
bit1.modify(i, k, cnt[k - j][up[i][j] - ]);
}
}
} printf("Case #%d: %lld\n", cas, * ans);
}
return ;
} /*
*/
hdu 5116 计数的更多相关文章
- 动态规划(DP计数):HDU 5116 Everlasting L
Matt loves letter L.A point set P is (a, b)-L if and only if there exists x, y satisfying:P = {(x, y ...
- hdu 5174(计数)
Ferries Wheel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 5116 Everlasting L
题目链接:HDU-5116 题意:给定若干个整数点,若一个点集满足P = {(x, y), (x + 1, y), . . . , (x + a, y), (x, y + 1), . . . , (x ...
- hdu 5072 计数+容斥原理
/* 题意: 给出n个数(n<100000), 每个数都不大于100000,数字不会有重复.现在随意抽出3个,问三个彼此互质 或者 三个彼此不互质的数目有多少. 思路: 这道题反着想,就是三个数 ...
- 2014ACM/ICPC亚洲区北京站题解
本题解不包括个人觉得太水的题(J题本人偷懒没做). 个人觉得这场其实HDU-5116要比HDU-5118难,不过赛场情况似乎不是这样.怀疑是因为老司机带错了路. 这套题,个人感觉动态规划和数论是两个主 ...
- hdu 5868 Polya计数
Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu 2865 Polya计数+(矩阵 or 找规律 求C)
Birthday Toy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
- HDU 4055 The King’s Ups and Downs(DP计数)
题意: 国王的士兵有n个,每个人的身高都不同,国王要将他们排列,必须一高一矮间隔进行,即其中的一个人必须同时高于(或低于)左边和右边.问可能的排列数.例子有1千个,但是最多只算到20个士兵,并且20个 ...
随机推荐
- stout代码分析之十:c++11之move和forward
stout中大量使用了c++11的特性,而c++11中move和forward大概是最神奇的特性了. 左值和右值的区别 ; // a是左值,0是右值 int b = rand(); // b是左值,r ...
- [技巧篇]21.Android Studio的快捷键设置[图片版]
如果对你有帮助,请点击推荐!
- 页面自适应<meta name="viewport">标签设置
viewport: 它在页面中设置,是应对手机模式访问网站.网页对屏幕而做的一些设置.通常手机浏览器打开页面后,会把页面放在一个虚拟的“窗 口”–这个比窗口大,也就是你常发现页面可以进行拖动.放大放小 ...
- Cppcheck代码分析上
1.检查点 1.自动变量检查: 返回自动变量(局部变量)指针: 2.越界检查:数组越界返回自动变量(局部变量)指针: 3.类检查:构造函数初始化: 4.内存泄露检查: 5.空指针检查: 6.废弃函数 ...
- svn: Checksum mismatch while updating 错误
最近使用svn客户端更新代码的时候出现 Checksum mismatch while updating 的错误 解决办法 在出错文件的目录下,用update to reversion , 先选onl ...
- jQuery中val()、text()、html()之间的差别
一.括号里没有值时表示取值 val获取表单中的值: text获取对象中的文本内容,不包含html标签: html获取对象中的内容,包括html标签 <!DOCTYPE HTML> & ...
- Druid连接池及监控在spring中的配置
Druid连接池及监控在spring配置如下: <bean id="dataSource" class="com.alibaba.druid.pool.DruidD ...
- CodeForces527D. Fuzzy Search
time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standa ...
- MSSQL备份脚本
) ) ) ),),':',''),' ',''),'-',''),'.','') set @name=N'DEMO'+@temp+'-完整 数据库 备份' set @disk=N'F:\Backup ...
- 边绘边理解prototype跟__proto__
网上流传着一张讲解prototype跟__proto__关系的图,尽管他已经描绘的很清楚了,但对于初学者来说,江太公感觉还是过于纠结,于是起心重绘,让他们之间的关系更加明晰可理解,一方面出于分享目的, ...