【CS Round #43 B】Rectangle Partition
【链接】https://csacademy.com/contest/round-43/task/rectangle-partition/
【题意】
水题
【题解】
横着过去,把相邻的边的宽记录下来.
竖着再扫描一遍,看看有没有出现和之前相同的宽度的.有的话,贡献的正方形个数++
【错的次数】
0
【反思】
在这了写反思
【代码】
#include<bits/stdc++.h>
using namespace std;
int h,w,n,m;
int x[100000+10],y[100000+10];
map<int,int>dic;
int main()
{
cin>>h>>w>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>x[i];
}
for(int i=1;i<=m;i++)
{
cin>>y[i];
}
sort(x+1,x+1+n);
n++;
x[n]=h;
sort(y+1,y+1+m);
m++;
y[m]=w;
int pre=0;
for(int i=1;i<=n;i++)
{
int temp=x[i]-pre;
dic[temp]++;
pre=x[i];
}
pre=0;
long long ans=0;
for(int i=1;i<=m;i++)
{
int temp=y[i]-pre;
ans=ans+dic[temp];
pre=y[i];
}
cout<<ans<<endl;
return 0;
}

浙公网安备 33010602011771号