Problem Statement | |||||||||||||
Surrounding Game is a single-player game played on a rectangular grid of cells. Cells are considered adjacent if they share a common side. (Hence, each cell has at most four adjacent cells. The cells on the sides and in the corners of the grid have fewer
adjacent cells than the ones inside the grid.) The game is played by placing stones into some of the cells. Each cell may only contain at most one stone. A cell is called dominated if at least one of the following two conditions holds:
Each cell of the grid contains two numbers, each from 0 to 9, inclusive: the cost of placing a stone into the cell, and the benefit from dominating the cell. At the end of the game, the overall score of the player is the sum of all benefits minus the sum of all costs. You are given the vector <string>s cost and benefit. The characters cost[i][j] and benefit[i][j] represent the two digits written in the cell (i,j). For example, if character 7 of element 4 of cost is '3', the cost of placing a stone into the cell (4,7) is 3. You are also given a vector <string> stone that describes the final state of the game. The character stone[i][j] is 'o' (lowercase letter oh) if the cell (i,j) contains a stone. Otherwise, stone[i][j] is '.' (a period). Calculate and return the overall score of the game. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | cost will contain between 2 and 20 elements, inclusive. | ||||||||||||
- | cost, benefit and stone will each contain the same number of elements. | ||||||||||||
- | Each element of cost will contain between 2 and 20 characters, inclusive. | ||||||||||||
- | Each element of cost will contain the same number of characters. | ||||||||||||
- | Each element of benefit and stone will contain the same number of characters as each element of cost. | ||||||||||||
- | Each character in cost and benefit will be a digit ('0'-'9'). | ||||||||||||
- | Each character in stone will either 'o' (lowercase letter oh) or '.'. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include<math.h>
#include<vector>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include <stdio.h>
using namespace std;
#define FOR(I,A,B) for (int I=int(A);I<int(B);I++)
#define PUSH(X,N,n) {FOR(q,0,N){X.push_back(n);}}
#define LL _int64
template<class T> T max (T A, T B){if(A>B) return A; else return B;}
template<class T> T min (T A, T B){if(A<B) return A; else return B;}
class
SurroundingGameEasy{
public:
int score(vector <string> cost, vector <string> benefit, vector <string> stone){
int i,j;
i=cost.size();j=cost[0].size();
int Ncost=0;//先算花费,再算得到
FOR( m,0,i){
FOR(n,0,j){
if(stone[m][n]=='o')
Ncost+=cost[m][n]-'0';}
}
int Nbenifit=0;
FOR( a,0,i){
FOR(b,0,j){
if(stone[a][b]=='o')
Nbenifit+=benefit[a][b]-'0';
else{
if(a-1<0||stone[a-1][b]=='o')
if(a+1>=i||stone[a+1][b]=='o')
if(b-1<0||stone[a][b-1]=='o')
if(b+1>=j||stone[a][b+1]=='o')
Nbenifit+=benefit[a][b]-'0';//一定要小心啊,字符和数字的转化
}
}
}
/**/
return Nbenifit-Ncost;
}
};
这道简单的,就是不熟练啊,花了40多分钟