' a753 最大面積 最多 AxB , 5<=A,B<=30
' 矩形一個 AXB ,查詢有 n 個, 每個高度為h 的最大面積,
' 如範例中 1的有7個、2的有5個、3的有6個、4的為0個 {1個的印0}
Dim A As Integer, B As Integer '矩形 A x B
Dim v(100, 100) As Integer '假設最大為 100x100
Private Sub Form1_Load( . . . ) Handles MyBase.Load
FileOpen(1, "in.txt", OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 1
If fn > 1 Then PrintLine(3) ' 第2個檔 in2 與 in1 之間換行
'只有一個矩形 nxm
Dim ab() = LineInput(fn).Split(" ") ' A x B h=0~9
A = ab(0) : B = ab(1)
' 數字以 空白 隔開
2016年7月29日 星期五
a753最大面積(C++版)
// a753 最大面積 最多 AxB , 5<=A,B<=30
// 矩形一個 AXB ,查詢有 n 個, 每個高度為h 的最大面積,
// 如範例中 1的有7個、2的有5個、3的有6個、4的為0個 {1個的印0}
#include <iostream>
using namespace std;
int di[]={-1,1,0,0};
int dj[]={0,0,-1,1};
int a[30][30];
int A,B , cnt;
void dfs(int i, int j, int h)
{
a[i][j]=0; ++cnt; // 設為0表示已走過 計數 +1
for(int d=0; d<4; ++d) //上下左右
// 矩形一個 AXB ,查詢有 n 個, 每個高度為h 的最大面積,
// 如範例中 1的有7個、2的有5個、3的有6個、4的為0個 {1個的印0}
#include <iostream>
using namespace std;
int di[]={-1,1,0,0};
int dj[]={0,0,-1,1};
int a[30][30];
int A,B , cnt;
void dfs(int i, int j, int h)
{
a[i][j]=0; ++cnt; // 設為0表示已走過 計數 +1
for(int d=0; d<4; ++d) //上下左右
a982迷宮問題(VB版)
Dim n As Integer ' n x n 方形
Dim a(100, 100) As Integer '假設最大為 100x100
Private Sub Form1_Load( . . . ) Handles MyBase.Load
FileOpen(1, "in.txt", OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 1
If fn > 1 Then PrintLine(3) ' 第2個檔 in2 與 in1 之間換行
Dim t As Short = LineInput(fn) ' t 筆
For k = 1 To t
n = LineInput(fn) ' n x n 迷宮
' 讀入:將#轉為-1、.轉為0 => a(i,j)
Dim a(100, 100) As Integer '假設最大為 100x100
Private Sub Form1_Load( . . . ) Handles MyBase.Load
FileOpen(1, "in.txt", OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 1
If fn > 1 Then PrintLine(3) ' 第2個檔 in2 與 in1 之間換行
Dim t As Short = LineInput(fn) ' t 筆
For k = 1 To t
n = LineInput(fn) ' n x n 迷宮
' 讀入:將#轉為-1、.轉為0 => a(i,j)
a982迷宮問題(C++版)
/*
a982 迷宮問題
*/
#include <iostream>
using namespace std;
const int MaxN = 100;
const int MaxQ = 200;
int main(void)
{
int n,i,j;
int x,y,h;
string s[MaxN];
int qh[MaxQ], qy[MaxQ] , qx[MaxQ];
int p , r ; // 頭,尾
a982 迷宮問題
*/
#include <iostream>
using namespace std;
const int MaxN = 100;
const int MaxQ = 200;
int main(void)
{
int n,i,j;
int x,y,h;
string s[MaxN];
int qh[MaxQ], qy[MaxQ] , qx[MaxQ];
int p , r ; // 頭,尾
C129 油田數(VB版)
Dim n As Integer, m As Integer 'n列 x m格
Dim a(100, 100) As Integer '假設最大為 100x100
Private Sub Form1_Load( . . .) Handles MyBase.Load
FileOpen(1, "in.txt", OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 1
If fn > 1 Then PrintLine(3) ' 第2個檔 in2 與 in1 之間換行
Dim t As Short = LineInput(fn) ' t 筆
For k = 1 To t
Dim nm() = LineInput(fn).Split(" ") ' n x m 油田 @油、*非
n = nm(0) : m = nm(1)
' 讀入:將@轉為1、*轉為0 => a(i,j)
C129 油田數(c++)
// c129 有幾處油田,另加印最大處的數量
#include <iostream>
using namespace std;
int di[]={-1,1,0,0,-1,1,-1,1}; //上,下,左,右,左上,左下,右上,右下
int dj[]={0,0,-1,1,-1,-1,1,1};
char a[100][101];
int m,n , cnt;
void dfs(int i, int j)
{
a[i][j]='*'; ++cnt;
// cout <<cnt<<'*' << i <<',' << j << endl;
#include <iostream>
using namespace std;
int di[]={-1,1,0,0,-1,1,-1,1}; //上,下,左,右,左上,左下,右上,右下
int dj[]={0,0,-1,1,-1,-1,1,1};
char a[100][101];
int m,n , cnt;
void dfs(int i, int j)
{
a[i][j]='*'; ++cnt;
// cout <<cnt<<'*' << i <<',' << j << endl;
2016年7月20日 星期三
dfs-1 (C++參考)
/*
dfs-1 A,B 水窪數及最大窪值
*/
#include <iostream>
using namespace std;
const int MaxN = 100;
int a[MaxN][MaxN] , m, n;
int dr[]={-1,1,0,0}; //列位移值: 上下左右
int dc[]={0,0,-1,1}; //行位移值: 上下左右
dfs-1 A,B 水窪數及最大窪值
*/
#include <iostream>
using namespace std;
const int MaxN = 100;
int a[MaxN][MaxN] , m, n;
int dr[]={-1,1,0,0}; //列位移值: 上下左右
int dc[]={0,0,-1,1}; //行位移值: 上下左右
dfs-1(vb版參考)
程式碼:
Dim a(100, 100) As Integer
Dim m As Integer, n As Integer
Private Sub Form1_Load( ... ) Handles MyBase.Load
FileOpen(1, "in1.txt", OpenMode.Input)
FileOpen(2, "in2.txt", OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 2 ' two in?.txt file
Dim t As Short = LineInput(fn) '每檔有 t 組資料
For k = 1 To t '處理 第k組
Dim mn() = LineInput(fn).Split(" ") '讀 m n
m = mn(0) : n = mn(1)
For i = 0 To m - 1 'm 列
Dim s = LineInput(fn) '讀入一列
Dim a(100, 100) As Integer
Dim m As Integer, n As Integer
Private Sub Form1_Load( ... ) Handles MyBase.Load
FileOpen(1, "in1.txt", OpenMode.Input)
FileOpen(2, "in2.txt", OpenMode.Input)
FileOpen(3, "out.txt", OpenMode.Output)
For fn = 1 To 2 ' two in?.txt file
Dim t As Short = LineInput(fn) '每檔有 t 組資料
For k = 1 To t '處理 第k組
Dim mn() = LineInput(fn).Split(" ") '讀 m n
m = mn(0) : n = mn(1)
For i = 0 To m - 1 'm 列
Dim s = LineInput(fn) '讀入一列
DFS應用-1
DFS應用-1: (A)有幾處水窪?上下左右算連通 (B)最大一處有多大{1個數數}?
(C,D)改成類似踩地雷(八方)算連通
0
|
1
|
2
|
3
|
4
|
5
|
6
|
0
|
1
|
2
|
3
|
4
|
5
|
6
|
0
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
|||||||||
0
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
||||||||||||||||||
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
0
|
1
|
2
|
3
|
4
|
0
|
1
|
2
|
3
|
4
|
|||||||||||
2
|
1
|
1
|
1
|
2
|
1
|
1
|
0
|
1
|
0
|
1
|
1
|
|||||||||||||||||||
3
|
1
|
1
|
3
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
|||||||||||||||||||
4
|
1
|
1
|
1
|
1
|
4
|
1
|
1
|
1
|
1
|
2
|
1
|
1
|
2
|
1
|
1
|
|||||||||||||||
5
|
1
|
5
|
1
|
1
|
3
|
1
|
1
|
1
|
1
|
|||||||||||||||||||||
6
|
1
|
1
|
1
|
1
|
6
|
1
|
1
|
1
|
1
|
4
|
1
|
1
|
1
|
|||||||||||||||||
讀入資料:空白處以0代替
Vb版→
|
in1.txt 第1列為2有兩組資料
|
in1.txt 第1列為2有兩組資料
|
||||
輸入→
C++版:
右列5組合成一個輸入檔
第1列為5
|
7 7
0000111
0110101
0010101
1010000
1010011
0000001
0111100
|
7 7
1000111
0110101
0010010
1100000
0011011
1000001
0111100
|
1 8
110000010
|
5 5
00001
01101
01001
11101
11001
|
3 5
01001
00110
01001
|
|
(A)輸出
|
5
|
9
|
2
|
2
|
5
|
|
(B)輸出
|
7
|
5
|
2
|
8
|
2
|
|
(C)輸出
|
5
|
4
|
2
|
2
|
1
|
|
(D)輸出
|
7
|
8
|
2
|
5
|
6
|
|