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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 1937 】Finding Seats(二维前缀和+尺取法)

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 1937 】Finding Seats(二维前缀和+尺取法) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

A group of K friends is going to see a movie. However, they are too late to get good tickets, so they are looking for a good way to sit all nearby. Since they are all science students, they decided to come up with an optimization problem instead of going on with informal arguments to decide which tickets to buy.?

The movie theater has R rows of C seats each, and they can see a map with the currently available seats marked. They decided that seating close to each other is all that matters, even if that means seating in the front row where the screen is so big it’s impossible to see it all at once. In order to have a formal criteria, they thought they would buy seats in order to minimize the extension of their group.?

The extension is defined as the area of the smallest rectangle with sides parallel to the seats that contains all bought seats. The area of a rectangle is the number of seats contained in it.?

They’ve taken out a laptop and pointed at you to help them find those desired seats.?

Input

Each test case will consist on several lines. The first line will contain three positive integers R, C and K as explained above (1 <= R,C <= 300, 1 <= K <= R × C). The next R lines will contain exactly C characters each. The j-th character of the i-th line will be ‘X’ if the j-th seat on the i-th row is taken or ‘.’ if it is available. There will always be at least K available seats in total.?
Input is terminated with R = C = K = 0.?

Output

For each test case, output a single line containing the minimum extension the group can have.

Sample Input

3 5 5 ...XX .X.XX XX... 5 6 6 ..X.X. .XXX.. .XX.X. .XXX.X .XX.XX 0 0 0

Sample Output

6 9

題目大意:

讓你找到最小的矩形體積,滿足在他范圍內存在至少k個 ' . '

解題報告:

? ? 這題思路比較詭異。

AC代碼:

#include<bits/stdc++.h>using namespace std; const int INF =0x3f3f3f3f; int minn; char tmp[1000 + 5][1000 + 5]; int maze[1000 + 5][1000 + 5]; int main() {int r,c,k;while(~scanf("%d%d%d",&r,&c,&k) ) {if(r+c+k == 0) break;memset(maze,0 ,sizeof(maze));minn = INF;for(int i = 1; i<=r; i++) {scanf("%s",tmp[i]+1);}for(int i = 1; i<=r; i++) {for(int j = 1; j<=c; j++) {tmp[i][j] == '.' ? maze[i][j] = 1 : maze[i][j] = 0;}} // for(int i = 1; i<=r; i++) { // for(int j = 1; j<=c; j++) { // printf("%d",maze[i][j]); // } // cout<<endl; // }for(int i = 1; i<=r; i++) {for(int j = 1; j<=c; j++) {maze[i][j] = maze[i][j] + maze[i-1][j] + maze[i][j-1] - maze[i-1][j-1];}} // for(int i = 1; i<=r; i++) { // for(int j = 1; j<=c; j++) { // printf("%d",maze[i][j]); // } // cout<<endl; // }int ll,rr;for(int i = 1; i <= r; i++)for(int j = i; j <= r; j++) {ll = 1; rr = 1;while(ll<=c && rr <=c) {while(maze[j][rr] - maze[j][ll-1] - maze[i-1][rr] + maze[i-1][ll-1]>=k && ll<=rr) {minn = min(minn,(j-i+1)*(rr-ll+1) );ll++;}rr++;}}printf("%d\n",minn);}return 0 ; }

?總結:

? ? ? 這道題難度也不能說大吧但是比較綜合,這年頭o(n^3)的方法基本不敢想。兩個小地方出了錯一個是二維前綴和的處理上寫成了maze[i][j] = maze[i][j] - maze[i-1][j] - maze[i][j-1] + maze[i-1][j-1]; ?第二個錯是在第二個while里面應該先更新minn再ll++,而不是先ll++再更新minn。

? ? ? 把符合要求的點抽象成1,不符合的抽象成0,這一技巧貌似很常用?

總結

以上是生活随笔為你收集整理的【HDU - 1937 】Finding Seats(二维前缀和+尺取法)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。