日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【HNOI2014】画框

發(fā)布時(shí)間:2024/4/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HNOI2014】画框 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題面

題解

這又是一種套路啊233

\(\sum a_i\)\(\sum b_i\)分別看做\(x\)\(y\),投射到平面直角坐標(biāo)系中,于是就是找\(xy\)最小的點(diǎn)

于是可以先找出\(x\)最小的點(diǎn)\(\mathrm{A}\)\(y\)最小的點(diǎn)\(\mathrm{B}\),然后找到在\(\mathrm{AB}\)下方的最遠(yuǎn)的點(diǎn)\(\mathrm{C}\)

\(\overrightarrow{\mathrm{AB}} \times \overrightarrow{\mathrm{AC}}\)最小
\[ \begin{aligned} \because \overrightarrow{\mathrm{AB}} \times \overrightarrow{\mathrm{AC}} &= (x_{\mathrm{B}} - x_{\mathrm{A}})(y_{\mathrm{C}} - y_{\mathrm{A}}) - (y_{\mathrm{B}} - y_{\mathrm{A}})(x_\mathrm{C} - x_\mathrm{A}) \\ &= (x_\mathrm B - x_\mathrm A) \times y_\mathrm C + (y_\mathrm A - y_\mathrm B) \times x_\mathrm C + y_\mathrm B x_\mathrm A - x_\mathrm B y_\mathrm A \end{aligned} \]
于是將權(quán)值改成\(\mathrm{g}[i][j] = (y_\mathrm A - y_\mathrm B) \times a[i][j] + (x_\mathrm B - x_\mathrm A)\times b[i][j]\),然后用\(\mathrm{KM}\)找出\(\mathrm C\)

找到\(\mathrm C\)之后用叉積判斷一下\(\mathrm C\)是不是在\(\mathrm{AB}\)的下方,如果是的話(huà),就遞歸處理\(\mathrm{AC, CB}\)

復(fù)雜度\(\mathrm{O}(\)能過(guò)\()\)

代碼

#include<cstdio> #include<cstring> #include<cctype> #include<algorithm> #include<climits> #define RG register #define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) #define clear(x, y) memset(x, y, sizeof(x))inline int read() {int data = 0, w = 1; char ch = getchar();while(ch != '-' && (!isdigit(ch))) ch = getchar();if(ch == '-') w = -1, ch = getchar();while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();return data * w; }const int N(75); int T, n, a[N][N], b[N][N], ans; struct vector { int x, y; }; inline vector operator - (const vector &lhs, const vector &rhs){ return (vector) {lhs.x - rhs.x, lhs.y - rhs.y}; } inline int operator * (const vector &lhs, const vector &rhs){ return lhs.x * rhs.y - lhs.y * rhs.x; } int g[N][N], lx[N], ly[N], visx[N], visy[N], match[N]; bool hungary(int x) {visx[x] = 1;for(RG int to = 1; to <= n; to++)if(!visy[to] && lx[x] + ly[to] == g[x][to]){visy[to] = true;if(!match[to] || hungary(match[to])) return (match[to] = x, true);}return false; }void build(int valx, int valy) {for(RG int i = 1; i <= n; i++) for(RG int j = 1; j <= n; j++)g[i][j] = -(valx * a[i][j] + valy * b[i][j]); }vector KM() {for(RG int i = 1; i <= n; i++)ly[i] = 0, lx[i] = *std::max_element(g[i] + 1, g[i] + n + 1);memset(match, 0, sizeof match);for(RG int x = 1; x <= n; x++)while(1){clear(visx, 0), clear(visy, 0);if(hungary(x)) break;int inc = INT_MAX;for(RG int i = 1; i <= n; i++) if(visx[i])for(RG int j = 1; j <= n; j++) if(!visy[j])inc = std::min(inc, lx[i] + ly[j] - g[i][j]);for(RG int i = 1; i <= n; i++) if(visx[i]) lx[i] -= inc;for(RG int i = 1; i <= n; i++) if(visy[i]) ly[i] += inc;}vector ans = (vector) {0, 0};for(RG int i = 1; i <= n; i++)ans.x += a[match[i]][i], ans.y += b[match[i]][i];return ans; }void solve(const vector &A, const vector &B) {build(A.y - B.y, B.x - A.x);vector C = KM(); ans = std::min(ans, C.x * C.y);if((B - A) * (C - A) >= 0) return;solve(A, C), solve(C, B); }int main() {T = read();while(T--){n = read();for(RG int i = 1; i <= n; i++)for(RG int j = 1; j <= n; j++)a[i][j] = read();for(RG int i = 1; i <= n; i++)for(RG int j = 1; j <= n; j++)b[i][j] = read();build(1, 0); vector A = KM();build(0, 1); vector B = KM();ans = std::min(A.x * A.y, B.x * B.y);solve(A, B); printf("%d\n", ans);}return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/cj-xxz/p/10395705.html

總結(jié)

以上是生活随笔為你收集整理的【HNOI2014】画框的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。