网站后台html页面,西安seo推广优化,武威网站建设,wordpress当前分类idcf1555B. Two Tables
题意#xff1a;
一个大矩阵空间内放置一个矩阵a#xff0c;现在要再往这个空间内放一个矩阵b#xff0c;a移动距离len才能放下b#xff0c;问len最小是多少
题解#xff1a;
不难发现左右或上下移动是最佳的#xff0c;斜着移动是最不好的。此时…cf1555B. Two Tables
题意
一个大矩阵空间内放置一个矩阵a现在要再往这个空间内放一个矩阵ba移动距离len才能放下b问len最小是多少
题解
不难发现左右或上下移动是最佳的斜着移动是最不好的。此时我们就需要判断左右移动是否有足够的空间并且移动后是否可以安放b b的安防一定是靠着墙角的
代码
// Problem: B. Two Tables
// Contest: Codeforces - Educational Codeforces Round 112 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1555/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Data:2021-08-16 23:47:26
// By Jozky#include bits/stdc.h
#include unordered_map
#define debug(a, b) printf(%s %d\n, a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pairint, int PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll 1e18;
const int INF_int 0x3f3f3f3f;
void read()
{
}
template typename _Tp, typename... _Tps void read(_Tp x, _Tps... Ar)
{x 0;char c getchar();bool flag 0;while (c 0 || c 9)flag| (c -), c getchar();while (c 0 c 9)x (x 3) (x 1) (c ^ 48), c getchar();if (flag)x -x;read(Ar...);
}template typename T inline void write(T x)
{if (x 0) {x ~(x - 1);putchar(-);}if (x 9)write(x / 10);putchar(x % 10 0);
}
void rd_test()
{
#ifdef LOCALstartTime clock();freopen(in.txt, r, stdin);
#endif
}
void Time_test()
{
#ifdef LOCALendTime clock();printf(\nRun Time:%lfs\n, (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
int main()
{//rd_test();int t;read(t);while (t--) {int a, b, x1, x2, y1, y2, a1, b1, a2, b2;read(a);read(b);cin x1 y1 x2 y2 a2 b2;a1 x2 - x1;//矩阵a的长b1 y2 - y1;//矩阵a的宽if (a1 a2 a b1 b2 b) {//如果矩阵a和矩阵b长宽加起来会超出空间printf(-1\n); //超界continue;}int ans 0x3f3f3f3f;if (a1 a2 a) { //横向移动不会出界if (x1 a2 || x2 a2 a)ans 0; //不用移动elseans min(ans, min(a2 - x1, x2 a2 - a)); //左右移动取最小}if (b1 b2 b) {if (y1 b2 || y2 b2 b)ans 0;elseans min(ans, min(b2 - y1, y2 b2 - b));}printf(%d.000000000\n, ans);}return 0;//Time_test();
}