$ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) 矩阵,有 \(q\) 次询问,每次给出一个矩形 $ x_1, x_2, y_1, y_2$ ,求有多这个矩形的有多少个全 \(0\) 子矩形 \(1 \leq n, m \leq 50, 1 \leq q \leq 3 \times 10^5\) 解题思路 : 设 \(g(x, y, l, r)\) 表示以…
题意,有n只袋鼠,没每只袋鼠有个袋子,大小为si,一个袋鼠可以进入另外一个袋鼠的袋子里面,当且仅当另一个袋鼠的袋子是他的二倍或二倍一上,然后中国袋鼠就是不可见的,不能出现多个袋鼠嵌套的情况.让你求最少可见袋鼠的数量. 解题方法是先排序再贪心,贪心策略是从中间开始贪心. #include <stdio.h> #include <algorithm> const int maxn = 500005; using namespace std; int s[maxn]; int n; in…
D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output There is an n × m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call t…
Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 Description We are given a figure consisting of only horizontal and vertical line segments. Our goal is to count the number of all different rectangles…
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 contains eighteen rectangles: Although there exists no rectangular grid that contains exactly two million rectangles, find the area of the grid with the…
Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3Seconds   Given n points on the XY plane, count how many regular rectanglesare formed. A rectangle is regular if and only if its sides are all paralle…
10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保存这些边两点的y坐标y1, y2.之后把这些边按y1排序,再按y2排序.用O(n)的方法找出有几个连续的y1, y2都相等.那么这些边两两是能构成矩形的.为C2cnt种.然后累加起来就是答案 代码: #include <stdio.h> #include <string.h> #inc…
Codeforces 954H Path Counting LINK 题目大意:给你一棵n层的树,第i层的每个节点有a[i]个儿子节点,然后问你树上的简单路径中长度在1~n*2-2之间的每个有多少条 因为直接计算过每个节点的路径并不好算 所以可以算一算从每个节点出发的路径的个数 f[i][j]表示对于在i层的1个节点,向下走行走j步的方案数 g[i][j]表示对于在i层的1个节点,第一步向上行走共走j步的方案数 然后DP式子比较显然 f[i][j]=a[i]∗f[i+1][j−1] g[i][j…
codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #include<queue> #include<cmath> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorith…
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问(a,b,c,d),问你: 在以(a,b)为左上角,以(c,d)为左下角,围成的矩形范围中,有多少全是0的矩形. 题解: 这题是dp套dp…… 首先解决dp1: 表示状态: f[a][b][c][d] = Rectangles number 表示左上角为(a,b),右下角的范围在(c,d)以内的全0矩形的个数.…
http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下角,左上角不超过i,j有多少矩形,然后询问的时候枚举右下角就可以了 #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<iostream> i…
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal is to count the number of all different rectangles formed by these segments. As an example, the number of rectangles in the Figures 1 and 2 are 5 and…
题目链接: B. Searching Rectangles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Filya just learned new geometry object — rectangle. He is given a field consisting of n × n unit cells. Rows ar…
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular if and only if its sides are all parallel to the axis.InputThe first line contains the number of tests t (1 ≤ t ≤ 10). Each case contains a single lin…
A (被装的袋鼠不可以装的袋鼠)贪心,排序,从n/2分成两部分. B 好一道前缀和的题目. C 标准算法不难想,m^2的算法见http://codeforces.com/blog/entry/9907#comment-153963 D dfs序的应用,详情自行搜索. E 反演变换.…
http://codeforces.com/problemset/problem/335/E (题目链接) 题意 懒得写了= = Solution 这题咋不上天= =. 参考题解:http://blog.csdn.net/clover_hxy/article/details/62217674 对于第一问,有另一种比较容易懂的想法: 假设Bob即将走一条高度为h的溜索(此时他所在的大楼高度>=h),这条溜索的长度期望是多少? 此时Bob站在这条溜索的左端点,而未知的部分只有溜索越过的大楼和溜索的右…
题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对.于是,对于一个数列a[1..n],给定m次操作.对于每一次操作,给定l,r(1≤l<r≤n),将序列a[l..r]倒置.求倒置后的逆序对的数量的奇偶性. 题解: 假设现在我们有一个序列并翻转这个序列[l,r]区间里面的数.假设某个数的k值是指在这个值后面小于这个数的数的个数,其实我们可以发现对于[1,l…
题目链接  Path Counting 题意  给定一棵高度为$n$的树,给出每一层的每个点的儿子个数(某一层的所有点儿子个数相同).   令$f_{k}$为长度为$k$的路径条数,求$f_{1}, f_{2}, ..., f_{2n-2}$. 考虑DP,设$f[i][j]$为从深度为$i$的点出发背对以$i$为根的子树(即任何时候都不进入以$i$为根的子树)走$j$步之后可以到达的点的个数. (同一条边最多走一次) 那么$f[i][j] = f[i-1][j-1] + calc(i-1, j-…
区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<in…
Discription You are given a tree consisting of nn vertices. A number is written on each vertex; the number on vertex ii is equal to aiai. Let's denote the function g(x,y)g(x,y) as the greatest common divisor of the numbers written on the vertices bel…
[链接] 我是链接,点我呀:) [题意] 如果a[i]*2<=a[j]那么i袋鼠可以装进j袋鼠里面 每只袋鼠都只能装一只袋鼠 [题解] 假设最后的方案是(ai,bi) 这里(ai,bi)表示下标为ai的袋鼠可以装进下标为bi的袋鼠里面 (这里袋鼠已经按照大小从小到大排序了) 则我们会发现,如果有(a1,b1),(a2,b2)...(ak,bk)这些方案的话(且这些方案合法) 我们总能让这个方案变成 a1~ak=1,2,3...k b1~bk=n-k+1,n-k+2,n-k+3...n 因为对于每…
题意,给出一个n行m列的矩阵 里面元素是0或者1 给出q个询问 a,b,c,d 求(a,b)到(c,d)有多少个由0组成的矩形 我们定义 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTc3NTY5MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">即为求(a,b)到(c,d)有多少个由0组成的…
传送门 看到 $n<=5000$,直接暴力枚举左右两条竖线 然后考虑怎么计算高度在某个范围内,左端点小于等于某个值,右端点大于等于某个值的横线数量 直接用权值树状数组维护当前高度在某个区间内的横线数量 考虑先固定左边的竖线,然后枚举从左到右枚举右边的竖线,那么随着右边竖线的右移,合法的横线(右端点大于等于某个值的横线)数量只会越来越少 所以枚举右边竖线的时候同时动态维护一个指向当前最左的右端点合法的横线,然后动态维护树状数组就行了 答案也很容易计算,在固定了左右竖线的情况下,设中间有 $p$ 个…
https://codeforc.es/contest/1194/problem/E 给5000条正常的(同方向不会重叠,也不会退化成点的)线段,他们都是平行坐标轴方向的,求能组成多少个矩形. 先进行坐标偏移,按水平线和垂直线分好类. 用扫描线的思路,从底部的水平线开始往上扫,先标记所有与该条水平线相交的竖直线,加入队列,给竖直线按y排序. 先把结束的竖直线undo掉,然后从这条水平线A的下一条水平线B开始,询问B线覆盖的区间中还有多少标记的竖直线. 注意要么偏移5001,要么把区间查询这里加个…
题意: 给你n条平行于坐标轴的线,问你能组成多少个矩形,坐标绝对值均小于5000 保证线之间不会重合或者退化 思路: 从下到上扫描每一条纵坐标为y的水平的线,然后扫描所有竖直的线并标记与它相交的线,保证上端至少多出1 并用树状数组维护它们 然后从y+1网上扫描纵坐标为yy的水平的线,查询y到yy中同时与他们相交的竖直的线的条数算贡献即可 每查询完一个yy后,要在树状数组内删除上端点为yy的竖直的线,因为以后的yy与它不会再相交了 代码: 几乎是照着官方题解来的.. #include<iostre…
题意 给定 \(n\) 个点的无向带权完全图,边权为 \(1\sim\frac{n(n-1)}{2}\).对于满足 \(1\leq k\leq n\) 的每个 \(k\) 求出将原图划分成 \(k\) 个组的方案数,满足组间边的权大于组内边的权值,答案对 \(998244353\) 取模. \(\texttt{Data Range:}1\leq n\leq 1500\) 题解 这个题蛮好的,只是我赛时没有想出来(甚至差点没有看懂题目),果然还是我太菜了/kk 首先从小到大把边加进来,然后可以发现…
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Friends  模拟 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long ll;…
D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output There is an n × m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call t…
CF传送门 因为洛谷题库未更新,所以给出的题面都是CF的. 现场打真是太卡了(梯子挂了,codeforc.es也崩了),所以五六分钟才打开题目 \(qwq\) A. Spell Check 萌萌题,把字符串放桶里,判名字每个字母是否恰好出现一次即可. \(9min\) \(AC\) \(qwq\) 都怪CF Code: #include<bits/stdc++.h> #define ll long long using namespace std; string s; int t[150],T…
Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮:使得\(x=x+k\) '√'按钮:使得\(x=\sqrt{x}\),此时\(x\)必须是平方数,游戏等级加1,即\(k=k+1\),且\(\sqrt{x}\)是\(k+1\)的倍数. 游戏开始时,\(x=2,k=1\),输出\(n(n \le 10^5)\)个数,表示每个等级对应的\(\frac…