1 条题解
-
5
本题唯一难点在于推出矩形边长的公式,另外还需注意,跑完正常的全排列后,要把矩形的长宽交换一下再跑全排列 以下全5种情况(第5种有两种子情况):
1. ┌─┐ ┌─┐ ┌─┤ │ │ ├─┤ │ │ │1│2│3│4│ │ │ │ │ │ └─┴─┴─┴─┘
2. ┌─┐ ┌─┐ │ │ │ ├──┤ │ │2│3 │4│ ┌─┴─┴──┴─┤ │ 1 │ └────────┘
3. ┌─┐ ┌─┐ │ │ │ ├──┤ │ │2│3 │4│ ┌─┴─┴──┤ │ │ 1 │ │ └──────┴─┘
4. ┌─┐ │2├──┐ ┌─┐ │ │ │ │ ├─┴─┤ │ │1│ 3 │4 │ │ │ │ │ └─┴───┴──┘
5.(1)┌───────┐ │ 3 │ └────┬──┤ ┌──┤ │ │1 │4 │ ┌┴──┤ │ │ 2 │ │ └───┴──┘
显然,此时
(2) ┌────┐ ┌───┤ 3 │ │ │ │ │ 1 ├───┬┘ ┌─┴───┤ │ │ 2 │ 4 │ └─────┴───┘
当然,也要不满足(1)的条件,且满足
本蒟蒻代码十分SHIT将就看吧#include <bits/stdc++.h> using namespace std; int num=0,ans=2147483647,a[5],b[5],now[5]; struct maxn{ int ma,mb; }f[10001]; bool cmp(maxn x,maxn y) { return x.ma<y.ma; } void check(int na,int nb) { if (ans>na*nb){ ans=na*nb; num=1; f[num].ma=min(na,nb); f[num].mb=max(na,nb); } else if (ans==na*nb){ bool flag=1; for (int i=1;i<=num;i++){ if (f[i].ma==min(na,nb) && f[i].mb==max(na,nb)){ flag=0; } } if (flag){ f[++num].ma=min(na,nb); f[num].mb=max(na,nb); } } } int main() { for (int i=1;i<=4;i++){ cin>>a[i]>>b[i]; } for (int first=0;first<=1;first++){ if (first) swap(a[1],b[1]); for (int second=0;second<=1;second++){ if (second) swap(a[2],b[2]); for (int third=0;third<=1;third++){ if (third) swap(a[3],b[3]); for (int fourth=0;fourth<=1;fourth++){ if (fourth) swap(a[4],b[4]); //上面是交换长和宽 for (int one=1;one<=4;one++){ now[1]=one; for (int two=1;two<=4;two++){ if (two==one) continue; now[2]=two; for (int three=1;three<=4;three++){ if (two==three || one==three) continue; now[3]=three; for (int four=1;four<=4;four++){ if (one==four || two==four || three==four) continue; now[4]=four; int na,nb; //Case 1 na=max(max(a[now[1]],a[now[2]]),max(a[now[3]],a[now[4]])); nb=b[now[1]]+b[now[2]]+b[now[3]]+b[now[4]]; check(na,nb); //Case 2 na=a[now[1]]+max(a[now[2]],max(a[now[3]],a[now[4]])); nb=max(b[now[1]],b[now[2]]+b[now[3]]+b[now[4]]); check(na,nb); //Case 3 na=max(a[now[1]]+max(a[now[2]],a[now[3]]),a[now[4]]); nb=b[now[4]]+max(b[now[1]],b[now[2]]+b[now[3]]); check(na,nb); //Case 4 na=max(max(a[now[1]],a[now[4]]),a[now[2]]+a[now[3]]); nb=b[now[1]]+b[now[4]]+max(b[now[2]],b[now[3]]); check(na,nb); //Case 5 na=max(a[now[1]]+a[now[2]],a[now[3]]+a[now[4]]); if (a[now[4]]>=a[now[1]]+a[now[2]]){ nb=max(max(b[now[1]],b[now[2]])+b[now[4]],b[now[3]]); } else if (a[now[2]]<=a[now[4]]){ nb=max(max(b[now[1]],b[now[2]])+b[now[4]],b[now[1]]+b[now[3]]); } check(na,nb); } } } } } } } } cout<<ans<<endl; sort(f+1,f+1+num,cmp); for (int i=1;i<=num;i++){ cout<<f[i].ma<<' '<<f[i].mb<<endl; } }
- 1
信息
- ID
- 16
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 21
- 已通过
- 4
- 上传者