O
O O
OO OO
the answer is the sum of (value * depth)
So the bigger the value is the topper the depth is.
Like the problem: Fence Repair
//By momo #include<cstdio> #include<algorithm> using namespace std; char a[100][100], b[100][100]; int main(){ int n, m, n2, m2; scanf("%d%d", &n, &m); for(int i = 0; i < n; i++) scanf("%s", a[i]); scanf("%d%d", &n2, &m2); for(int i = 0; i < n2; i++) scanf("%s", b[i]); int bst = -1, bsx, bsy; for(int x = -50; x <= 50; x++){ for(int y = -50; y <= 50; y++){ int sum = 0; for(int i = 0; i < n && i+x < n2; i++){ if(i+x < 0) continue; for(int j = 0; j < m && j+y < m2; j++){ if(j+y < 0) continue; sum += (a[i][j]-'0') * (b[i+x][j+y]-'0'); } } if(sum > bst){ bst = sum; bsx = x; bsy = y; } } } printf("%d %d\n", bsx, bsy); }
沒有留言:
張貼留言