cf1555B. Two Tables
生活随笔
收集整理的這篇文章主要介紹了
cf1555B. Two Tables
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
cf1555B. Two Tables
題意:
一個大矩陣空間內(nèi)放置一個矩陣a,現(xiàn)在要再往這個空間內(nèi)放一個矩陣b,a移動距離len才能放下b,問len最小是多少
題解:
不難發(fā)現(xiàn)左右或上下移動是最佳的,斜著移動是最不好的。此時我們就需要判斷左右移動是否有足夠的空間,并且移動后是否可以安放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 pair<int, 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(); }總結(jié)
以上是生活随笔為你收集整理的cf1555B. Two Tables的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国产统一操作系统(UOS)安装、体验
- 下一篇: cf1555C Coin Rows