给出 n 个矩形的长和宽,求有多少对(i,j,k)满足:
代码:
#include<bits/stdc++.h>
#define ll long long
#define landingyu work();
#define AK return
#define IOI 0;
#define inf 0x3f3f3f3f
#define eps 0.00001
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
void write(int x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)write(x/10);
putchar(x%10+'0');
}
struct rectangle{
int x;
int y;
}a[60];
int n,ans;
bool check(int i,int j,int k){
if(a[j].y+a[k].y>a[i].y && a[j].x+a[k].x>a[i].x) return false;
if(a[j].x>a[i].x || a[j].y>a[i].y) return false;
if(a[k].x>a[i].x || a[k].y>a[i].y) return false;
return true;
}
void work(){
n=read();
for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
if(i!=j && j!=k && i!=k){
if(check(i,j,k)){
ans++;
// cout<<i<<" "<<j<<" "<<k<<endl;
continue;
}
swap(a[j].x,a[j].y);
if(check(i,j,k)){
ans++;
// cout<<i<<" "<<j<<" "<<k<<endl;
continue;
}
swap(a[k].x,a[k].y);
if(check(i,j,k)){
ans++;
// cout<<i<<" "<<j<<" "<<k<<endl;
continue;
}
swap(a[j].x,a[j].y);
if(check(i,j,k)){
ans++;
// cout<<i<<" "<<j<<" "<<k<<endl;
continue;
}
}
cout<<ans;
}
int main(){landingyu AK IOI}
应该是check函数出错了,但是构造不出错误数据,望大佬们不吝赐教。
注:禁止 无意义回复 / 讨论代码最后一行