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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Fire Net

發(fā)布時間:2025/6/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Fire Net 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Fire Net

Time Limit : 2000/1000ms (Java/Other)???Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 10???Accepted Submission(s) : 3

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.

A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening.

Here we assume that a bullet is so powerful that it can run across any distance and destroy a blockhouse on its way. On the other hand, a wall is so strongly built that can stop the bullets.

The goal is to place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map unless there is at least one wall separating them. In this problem we will consider small square cities (at most 4x4) that contain walls through which bullets cannot run through.

The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of blockhouses in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways.



Your task is to write a program that, given a description of a map, calculates the maximum number of blockhouses that can be placed in the city in a legal configuration.

Input

The input file contains one or more map descriptions, followed by a line containing the number 0 that signals the end of the file. Each map description begins with a line containing a positive integer n that is the size of the city; n will be at most 4. The next n lines each describe one row of the map, with a '.' indicating an open space and an uppercase 'X' indicating a wall. There are no spaces in the input file.

Output

For each test case, output one line containing the maximum number of blockhouses that can be placed in the city in a legal configuration.

Sample Input

4 .X.. .... XX.. .... 2 XX .X 3 .X. X.X .X. 3 ... .XX .XX 4 .... .... .... .... 0

Sample Output

5 1 5 2 4 題意: 給出你正方形的邊長格數(shù)(n<=4),并在隨機在某些位置放上墻,除了由墻隔開的,一個十字架方向上不能重,問你最多能放多少架大炮。 分析: 計算出每個空位的十字架方向上有多少個空位,即:將會有多少會與其沖突。然后排序選擇十字架方向上空位最少的位置,(最少的位置干擾最少,最有可能架大炮)開始判斷是否能夠放大炮。 因此,該函數(shù)包括兩個最重要的函數(shù):count(計數(shù)),bool right(判斷是否正確) 計數(shù)時:要判斷四個方向,遇墻break。 bool right:也要判斷四個方向,遇墻break,如果遇到map[][]=1,說明該圖此位置已有大炮,返回false,否則檢測到最后都行返回true。如果該位置可以的話要將map中的數(shù)置為1,作為標記。 代碼:

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;/*
int cmp(const void *a,const void *b){
??????? return *(int*)a-*(int*)b;
}*/
int count(int a[4][4],int row,int col,int n){/*數(shù)數(shù),計算每個空位,十字架方向上所有能夠放的,即會發(fā)生沖突的數(shù)目*/
??? int count1=0,i;/*注意四個方向,count計數(shù),別忘了設(shè)初值為0*/
??? for(i=row-1;i>=0;i--){/*up*/
??????? if(a[i][col]==2)/*碰到墻才會停止*/
??????????? break;
??????? else
??????????? count1++;
??? }
??? for(i=row+1;i<n;i++){/*down*/
??????? if(a[i][col]==2)
??????????? break;
??????? else
??????????? count1++;
??? }
??? for(i=col-1;i>=0;i--){/*left*/
??????? if(a[row][i]==2)
??????????? break;
??????? else
??????????? count1++;
??? }
??? for(i=col+1;i<n;i++){/*right*/
??????? if(a[row][i]==2)
??????????? break;
??????? else
??????????? count1++;
??? }
??? return count1;
}
bool right(int a[4][4],int row,int col,int n){/*判斷是否可以安置炮*/
??? int i;
??????? for(i=row-1;i>=0;i--){/*用bool型*/
??????? if(a[i][col]==1)/*十字架方向上碰到架炮的地方,就說明有沖突,即此處不可行*/
??????????? return false;
??????? else if(a[i][col]==2)/*碰到墻停止*/
??????????? break;
??? }
??? //down
??? for(i=row+1;i<n;i++){/*仍舊是四個方向上檢測*/
??????? if(a[i][col]==1)
??????????? return false;
??????? else if(a[i][col]==2)
??????????? break;
??? }
??? //left
??? for(i=col-1;i>=0;i--){
??????? if(a[row][i]==2)
??????????? break;
??????? else if(a[row][i]==1)
??????????? return false;
??? }
??? //right
??? for(i=col+1;i<n;i++){
??????? if(a[row][i]==2)
??????????? break;
??????? else if(a[row][i]==1)
??????????? return false;
??? }
??? return true;
}
int main(){
??? int n,i,j,k,ans;
??? char c;
??? int map[4][4];
??? int cnt[4][4];
??? while(scanf("%d",&n),n){
??????? k=0,ans=0;
??????? memset(cnt,-1,sizeof(cnt));
??????? for(i=0;i<n;i++){
??????????? for(j=0;j<n;j++){
?????????????? // scanf("%c",&c);
??????????????? cin>>c;
??????????? if(c=='.'){/*將字符型的圖轉(zhuǎn)化成數(shù)組型的*/
??????????????? k++;/*順表記錄下總共有多少個空的位置,方便最后檢測成不成功時的循環(huán)次數(shù)*/
??????????????? map[i][j]=0;/*0表示可放的位置*/
??????????? }
??????????? else if(c=='X')/*X表示墻的位置*/
??????????????? map[i][j]=2;
??????????? }
??????? }
??????? for(i=0;i<n;i++){/*計數(shù),遇墻跳過,遇空地計數(shù),并將地址與數(shù)目用二維數(shù)組cnt[i][j]保留下來*/
??????????? for(j=0;j<n;j++){
??????????????? if(map[i][j]==2)
??????????????????? continue;
??????????????? else
??????????????????? cnt[i][j]=count(map,i,j,n);
??????????? }
??????? }
??????? /*qsort(cnt,n*n,sizeof(cnt[0][0]),cmp);//!!!不能使用qsort直接對cnt排序,否則將會把位置給弄丟,所以應(yīng)該使用冒泡排序*/
???????? int min=7,mini,minj;/*最多只能是6,用題中的最大可能做最小箱的箱底*/
???????? while(k--){/*有k個空位,即有k種可能性,每個位置都要判斷下*/
??????????? for(i=0;i<n;i++){
??????????????? for(j=0;j<n;j++){
??????????????????? if(cnt[i][j]==-1)
??????????????????????? continue;
??????????????????? else if(cnt[i][j]<min){/*要先排排序,從最小的開始,使用貪心,因為周圍的可能最少,該位成功的可能性最大*/
??????????????????????? min=cnt[i][j];/*重置最小*/
??????????????????????? mini=i;/*記錄位置*/
??????????????????????? minj=j;
??????????????????? }
??????????????? }
??????????? }
??????????? if(right(map,mini,minj,n)){/*判斷是否能夠放*/
??????????????? map[mini][minj]=1;/*可以的話,就將map中的該位置為1,標志為有炮,便于剩下位置的判斷*/
??????????????? ans++;/*成立計數(shù)加1*/
??????????? }
??????????? cnt[mini][minj]=-1;/*該位置不用再檢測了,在cnt數(shù)組中標記下-1,直接跳過,檢測第二個最小的位置*/
??????????? min=7;/*重置最小*/

??????? }
??????? /*“。”點表示可放東西,總計有多少個空,k個*/
/*??????????? for(i=0;i<n;i++){
??????????????? for(j=0;j<n;j++){
??????????????????? if(cnt[i][j]==-1)
??????????????????????? continue;
??????????????????????? else if(right(map,i,j,n)){
??????????????????????????? map[i][j]=1;
??????????????????????????? ans++;
??????????????????????? }


??????????????? }
??????????? }*/
??????? printf("%d\n",ans);/*輸出*/
??? }

return 0;
}

轉(zhuǎn)載于:https://www.cnblogs.com/money-lady/p/3659076.html

總結(jié)

以上是生活随笔為你收集整理的Fire Net的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 久久精品国产亚洲AV成人雅虎 | 亚洲一级影院 | 艳妇臀荡乳欲伦交换gif | 挪威xxxx性hd极品 | 日本欧美激情 | 国产一区免费观看 | 裸体女人a级一片 | 日韩成人av网 | 亚洲精品视频一二三区 | 干成人网 | 青青av在线 | 久久网一区 | 久久国产二区 | 看片免费黄在线观看入口 | 日韩欧美中文一区 | 日韩乱码人妻无码系列中文字幕 | 91官网在线| 青青草午夜 | 可以免费看的黄色 | 丁香综合 | 亚洲日本一区二区三区 | 欧美少妇在线 | 日韩一级视频在线观看 | 国产91啪 | www天天干 | 欧美狠狠干 | 国产九九精品视频 | 天堂在线中文8 | 波多野结衣免费看 | 亚洲精品天堂成人片av在线播放 | 99久久视频| 日韩草逼视频 | 日韩青青草 | 天天操天天操天天 | 久久久亚洲综合 | 国产sm在线观看 | 欧美日韩欧美 | 粉嫩av在线| 久久久无码精品亚洲国产 | 亚洲国产日韩欧美在线观看 | 久久精品在线播放 | 毛片视频免费观看 | 日韩在线观看免费av | 国产精品一区二区电影 | 操人在线观看 | 日韩91av | 亚洲影院中文字幕 | 蜜桃视频在线观看污 | 欧美一区二区在线观看 | 国产九色| 一起操在线 | 99成人| 日日操日日 | 一区二区美女视频 | 国产内射老熟女aaaa∵ | 久久久免费av | 日本在线不卡一区 | 女同视频网站 | 裸体一区二区 | 中文字幕在线免费视频 | 中文字幕在线免费观看视频 | 国产妇女视频 | 成人在线观看国产 | 精品国产欧美日韩 | 水牛影视av一区二区免费 | 精久久久 | 国产乱了高清露脸对白 | 亚洲欧美激情一区二区三区 | 久久黄色影院 | 亚洲av成人精品一区二区三区 | 亚洲精品www久久久久久广东 | 日本特黄一级片 | 制服.丝袜.亚洲.另类.中文 | 亚洲国产欧美在线人成 | www在线观看国产 | 国产一区二区三区91 | 天天干视频在线观看 | √资源天堂中文在线 | 欧美激情另类 | 岛国裸体写真hd在线 | 黑人玩弄人妻一区二区三区影院 | 欧美性猛交xxxx免费看 | 久久天天综合 | 成人av免费播放 | 天天干天天要 | 亚洲三级久久 | 三级国产在线 | 女人性高潮视频 | 漂亮人妻洗澡被公强 日日躁 | 亚洲国产精品久久久久婷婷老年 | 在线免费观看视频 | 最新激情网 | 亚洲国产精品自拍视频 | 蜜臀av一区二区三区激情综合 | 欧美粗又大 | 亚洲最新在线 | 色九月婷婷 | www.色多多| 国产伦理在线 |