比赛AC: 03 09 10 11
1003 ioes+打表。。。
1009暴力判断
2.3.4.5.6情况即可
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x1,y1;
int x2,y2;
}e[6];
int main()
{
//freopen("1.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d %d %d %d %d %d",&e[1].x1,&e[1].y1,&e[1].x2,&e[1].y2,&e[2].x1,&e[2].y1,&e[2].x2,&e[2].y2);
// 2:重合
// puts("ok");
if(e[1].x1==e[2].x1&&e[1].y1==e[2].y1&&e[1].x2==e[2].x2&&e[1].y2==e[2].y2)
{
puts("2");
continue;
}
//3相离
if((e[2].x1>=e[1].x2||e[2].x2<=e[1].x1)||(e[2].y1>=e[1].y2||e[2].y2<=e[1].y1))
{
puts("3");
continue;
}
if(e[2].y1==e[1].y1&&e[2].y2<e[1].y2&&e[2].x1<e[1].x1&&e[2].x2>e[1].x2)
{
puts("5");//上12土
continue;
}
if(e[1].y1==e[2].y1&&e[1].y2<e[2].y2&&e[1].x1<e[2].x1&&e[1].x2>e[2].x2)
{
puts("5");//上21土
continue;
}
if(e[1].y2==e[2].y2&&e[1].y1<e[2].y1&&e[2].x1<e[1].x1&&e[2].x2>e[1].x2)
{
puts("5");//下12土
continue;
}
if(e[2].y2==e[1].y2&&e[2].y1<e[1].y1&&e[1].x1<e[2].x1&&e[1].x2>e[2].x2)
{
puts("5");//下21土
continue;
}
if(e[1].x2==e[2].x2&&e[1].x1<e[2].x1&&e[2].y1<e[1].y1&&e[2].y2>e[1].y2)
{
puts("5");//左12土
continue;
}
if(e[2].x2==e[1].x2&&e[2].x1<e[1].x1&&e[1].y1<e[2].y1&&e[1].y2>e[2].y2)
{
puts("5");//左21土
continue;
}
if(e[1].x1==e[2].x1&&e[1].x2>e[2].x2&&e[2].y2>e[1].y2&&e[2].y1<e[1].y1)
{
puts("5");//右12土
continue;
}
if(e[1].x1==e[2].x1&&e[2].x2>e[1].x2&&e[1].y2>e[2].y2&&e[1].y1<e[2].y1)
{
puts("5");//右21土
continue;
}
//6
if(e[2].x1<e[1].x1&&e[2].x2>e[1].x2&&e[2].y1>e[1].y1&&e[2].y2<e[1].y2)
{
puts("6");
continue;
}
if(e[1].x1<e[2].x1&&e[1].x2>e[2].x2&&e[1].y1>e[2].y1&&e[1].y2<e[2].y2)
{
puts("6");
continue;
}
if(e[1].y1==e[2].y1&&e[1].y2==e[2].y2)
{
if(e[1].x1>e[2].x1&&e[1].x2<e[2].x2)
{
puts("4");
continue;
}
if(e[2].x1>e[1].x1&&e[2].x2<e[1].x2)
{
puts("4");
continue;
}
}
if(e[1].x1==e[2].x1&&e[1].x2==e[2].x2)
{
if(e[1].y1>e[2].y1&&e[1].y2<e[2].y2)
{
puts("4");
continue;
}
if(e[2].y1>e[1].y1&&e[2].y2<e[1].y2)
{
puts("4");
continue;
}
}
if(e[1].x1<=e[2].x1&&e[1].y1<=e[2].y1&&e[1].x2>=e[2].x2&&e[1].y2>=e[2].y2)
{
puts("3");
continue;
}
if(e[2].x1<=e[1].x1&&e[2].y1<=e[1].y1&&e[2].x2>=e[1].x2&&e[2].y2>=e[1].y2)
{
puts("3");
continue;
}
puts("4");
}
}
想写下11的具体题解:
二分图解法:
首先 可以把人和他可以喝的奶茶连边,建立二分图。
结果肯定是二分图最大匹配数。
直接匈牙利算法肯定T。
然后我们发现一个定理:Hall's marriage theorem:
X是二分图的一边的点集合。W是X的任意一个子集,NG(W)是 于W相连的点的集合。
然后我们如果枚举班级的子集求出最大匹配数。肯定也是T的。
我们先求max(|W| - |NG(W)| )
观察后发现:W只有3种情况:
1:空集,结果为0。
2:点都在一个班级里,那么NG(W)=其他班级奶茶数和。是个定值,所以为了让这个数最大,所以我们肯定是选一个班所有人。
因为被减数不变,减数肯定越大结果越大。
3.如果选了至少2班的人,那么NG(W)=全部奶茶数。也是定值,所以不如全选。
所以全部情况等价于:全选,不选,选每个班所有人。
所以我们枚举每个班所有人就能线性的求出答案。
代码略: