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个 ...
随机推荐
- 【链表】在O(1)的时间删除链表的节点
/** * 在O(1)的时间删除链表的节点 * * @author * */ public class Solution { public static void deleteNode(Node he ...
- udhcpd源码分析3--IP租赁管理
1:重要的结构体 全局链表的成员struct dhcpOfferedAddr *leases 记录了当前租赁出去的IP信息 /* leases.h */ struct dhcpOfferedAddr ...
- sql 建表以及查询---复杂查询之成绩排名
废话不说,直接建表 1.表Player USE T4st -- 设置当前数据库为T4st,以便访问sysobjects IF EXISTS(SELECT * FROM sysobjects WHERE ...
- JavaScript实现35选7并记录历史状态
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAL4AAABQCAYAAACnOs9vAAAJy0lEQVR4nO2dbWwUxxnH/2c5SElQSl ...
- css预处理器和后处理器
因为我是前端刚入门,昨天看了一个大神写的的初级前端需要掌握的知识,然后我就开始一一搜索,下面是我对css预处理器和后处理器的搜索结果,一是和大家分享下这方面的知识,另一方面方便自己以后翻阅.所以感兴趣 ...
- kvm增加硬盘挂载
1.查询需要添加虚拟主机 [root@sz-kvm-110 images]# virsh list --all Id 名称 状态 ------- ...
- mysql varchar到底能存多少字符。
utf8编码的varchar Mysql记录行数据是有限的.大小为64k,即65535个字节,而varchar要用1-2字节来存储字段长度,小于255的1字节,大于255的2字节. Mysql 5.0 ...
- POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0 异常处理
在本机开发asp.net .rdlc报表后,部署到本地没有问题. 当把网站发布后部署在IIS上,新电脑上(只安装了.net framwork4.5),提示如下错误: “Could not load f ...
- MySQL按天,按周,按月,按时间段统计
MYSQL函数:DATE_FORMAT 例子: select DATE_FORMAT(create_time,'%Y%m%d') days,count(caseid) count from tc_ca ...