ACM-ICPC 2018 南京賽區網路預賽__B The writing on the wall【列舉】
- 2000ms
- 262144K
Feeling hungry, a cute hamster decides to order some take-away food (like fried chicken for only 30 Yuan).
However, his owner CXY thinks that take-away food is unhealthy and expensive. So she demands her hamster to fulfill a mission before ordering the take-away food. Then she brings the hamster to a wall.
The wall is covered by square ceramic tiles, which can be regarded as a n∗m grid. CXY wants her hamster to calculate the number of rectangles composed of these tiles.
For example, the following 3∗3 wall contains 3636 rectangles:
Such problem is quite easy for little hamster to solve, and he quickly manages to get the answer.
Seeing this, the evil girl CXY picks up a brush and paint some tiles into black, claiming that only those rectangles which don't contain any black tiles are valid and the poor hamster should only calculate the number of the valid rectangles. Now the hamster feels the problem is too difficult for him to solve, so he decides to turn to your help. Please help this little hamster solve the problem so that he can enjoy his favorite fried chicken.
Input
There are multiple test cases in the input data.
The first line contains a integer T : number of test cases. T≤5.
For each test case, the first line contains 3 integers n,m,k , denoting that the wall is a n×m grid, and the number of the black tiles is k.
For the next k lines, each line contains 2 integers: x y ,denoting a black tile is on the x-th row and y-th column. It's guaranteed that all the positions of the black tiles are distinct.
For all the test cases,
1≤n≤10^5,1≤m≤100,
0≤k≤10^5,1≤x≤n,1≤y≤m.
It's guaranteed that at most 2 test cases satisfy that n≥20000.
Output
For each test case, print "Case #x: ans" (without quotes) in a single line, where x is the test case number and ansans is the answer for this test case.
Hint
The second test case looks as follows:
樣例輸入
2
3 3 0
3 3 1
2 2
樣例輸出
Case #1: 36
Case #2: 20
題目來源
題目大意:一個n*m的方格矩陣,有的格子被塗成了黑色,問該矩陣中有多少個子矩陣,子矩陣不包含黑色格子
題解:列舉每個以(i,j)為右下角的矩陣的個數,具體細節看程式碼
AC的C++程式碼:
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=100002;
bool flag[N][105];
int up[105];
int main()
{
int T,n,m,k,x,y;
scanf("%d",&T);
for(int t=1;t<=T;t++){
memset(flag,false,sizeof(flag));
memset(up,0,sizeof(up));
scanf("%d%d%d",&n,&m,&k);
while(k--){
scanf("%d%d",&x,&y);
flag[x][y]=true;
}
ll ans=0;
for(int i=1;i<=n;i++){
//更新up陣列
for(int j=1;j<=m;j++)
if(flag[i][j])
up[j]=i;//第j列中為黑塊的行(在1~i行中取最大行標
for(int j=1;j<=m;j++){//統計以(i,j)為右下角的矩陣的個數
int h=INF;//統計矩陣長為k時高最大為多少
for(int k=1;k<=j;k++){//列舉矩陣的長
//j-k+1表示以(i,j)為右下角長為k的矩陣的左邊界下標
h=min(h,i-up[j-k+1]);//i-up[j-k+1]表示此列能取得的最大高
ans+=h;
}
}
}
printf("Case #%d: %lld\n",t,ans);
}
return 0;
}
相關文章
- ACM-ICPC 2018 徐州賽區網路預賽ACM
- ACM-ICPC 2018 瀋陽賽區網路預賽ACM
- ACM-ICPC 2018 南京賽區網路預賽__E AC Challenge【狀態壓縮+DP】ACM
- ACM-ICPC 2018 徐州賽區網路預賽 F. Features TrackACM
- ACM-ICPC 2018 南京賽區網路預賽__K The Great Nim Game【博弈論+費馬小定理+DP】ACMGAM
- ACM-ICPC 2018 南京賽區網路預賽 __G Lpl and Energy-saving Lamps【線段樹+模擬】ACMLAMP
- ACM-ICPC 2018 南京賽區網路預賽__J. Sum【尤拉篩法+質因子分解+思維】ACM
- ACM-ICPC 2018 南京賽區網路預賽__L. Magical Girl Haze 【Dijkstra演算法+分層圖思想】ACM演算法
- ACM-ICPC 2018 徐州賽區網路預賽 I. Characters with Hash【簽到題】ACM
- 2018 北京賽區網路預選賽 A. Saving Tang Monk II(BFS+優先佇列)佇列
- 2018icpc 南京網路賽L Magical Girl Haze
- 2018 瀋陽賽區網路預賽 I.Lattice's basics in digital electronics(模擬)Git
- 2018 ICPC南京區域賽題解 更新至 8 題
- 2019ICPC南京網路賽B super_log——擴充套件尤拉定理套件
- 2018 徐州網路賽 G 題解
- 第43屆ACM-ICPC國際大學生程式設計競賽 亞洲區域賽南京站現場賽名額分配相關說明ACM程式設計
- 2018華為網路技術大賽
- 2016中國“網際網路+”創業創新大賽(西北+山西)賽區決賽成功舉辦 優秀專案將會師海口...創業
- 2016中國“網際網路+”創業創新大賽(西北+山西)賽區決賽成功舉辦優秀專案將會師海口創業
- 2018藍橋杯省賽B組
- 為加快南京AI產業發展,2018全球(南京)人工智慧應用大賽現公開徵集賽題原型AI產業人工智慧原型
- 沙漠or綠洲,從南京軟博會I.D.Spark網際網路創新大賽看南京網際網路發展Spark
- 2024 ICPC 網路預選賽 第 2 場
- ICPC2018徐州網路賽 H.Ryuji doesn't want to study ( 樹狀陣列陣列
- 2020中國電信“天翼杯”網路安全攻防大賽初賽順利舉辦
- 2018 icpc徐州站網路賽 H Ryuji doesn't want to study
- 2018王者榮耀KPL秋季賽賽程表 2018王者榮耀KPL秋季賽賽制
- 第 43 屆 ACM-ICPC 亞洲區域賽(徐州)現場賽名額分配規則及相關說明ACM
- 新加坡政府將舉辦區塊鏈挑戰賽區塊鏈
- ACM-ICPC 2018 決賽落幕,中國戰隊一金兩銀戰績收官ACM
- 『№20181201賽事B』
- 新生賽及預選賽 10
- 第十四屆全國大學生資訊保安競賽創新實踐能力賽(華中賽區)比賽成功舉辦
- 【護航工業未來】中新賽克將助力2021年中國工業網際網路安全大賽舉辦
- Competition——網際網路比賽(程式設計相關):國內外各種網際網路比賽舉辦時間、條件、細節等詳細攻略程式設計
- 2024春秋杯網路安全聯賽夏季賽-PWN-Writeup
- 以賽代練 | 綠盟科技助力2021年金華市銀行業網路安全競賽成功舉辦行業
- 2024中國工業網際網路安全大賽智慧家電行業賽道選拔賽行業