搜索-洛谷P1034 矩形覆盖
https://daniu.luogu.org/problem/show?pid=1034
瞎几把想了半天,想出了一个可以过的暴搜方案,打着打着就萎了;
然后看题解,妈的全是瞎搞,然后4^50的暴搜加上优化有人过了;
然后我就去百度看看;
https://wenku.baidu.com/view/5f8961b47fd5360cba1adbeb.html
然后就知道这个是noip提高的题目;
说好k<=4,其实k最大只有3;
然后数据没有对每一种情况近判断性,所以本来300+的代码因为有些用不到可以变成100+;
我曹;
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define Ll long long
using namespace std;
int x[51],y[51];
int n,m,x1,x2,y1,y2;
void A(){
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
printf("%d",(x2-x1)*(y2-y1));
}
void B(){
int ans,sum=1e9;
for(int k=0;k<=500;k++){
ans=0;
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
if(x[i]>k)continue;
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
ans+=(x2-x1)*(y2-y1);
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
if(x[i]<=k)continue;
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
ans+=(x2-x1)*(y2-y1);
sum=min(sum,ans);
}
for(int k=0;k<=500;k++){
ans=0;
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
if(y[i]>k)continue;
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
ans+=(x2-x1)*(y2-y1);
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
if(y[i]<=k)continue;
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
ans+=(x2-x1)*(y2-y1);
sum=min(sum,ans);
}
printf("%d",sum);
}
void C(){
int ans,sum=1e9;
for(int k=0;k<=500;k++)
for(int j=k+1;j<=500;j++){
ans=0;
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
if(y[i]>k)continue;
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
ans+=(x2-x1)*(y2-y1);
// if(k==1&&j==2)cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl;
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
if(k>=y[i]||y[i]>j)continue;
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
ans+=(x2-x1)*(y2-y1);
// if(k==1&&j==2)cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl;
x1=y1=1e9;x2=y2=0;
for(int i=1;i<=n;i++){
if(y[i]<=j)continue;
x1=min(x1,x[i]);
x2=max(x2,x[i]);
y1=min(y1,y[i]);
y2=max(y2,y[i]);
}
if(x1==1e9)x1=x2=0;
// if(k==1&&j==2)cout<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl;
ans+=(x2-x1)*(y2-y1);
sum=min(sum,ans);
}
printf("%d",sum);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]);
if(m==1)A();
if(m==2)B();
if(m==3)C();
}