Chess
Almost everyone knows the problem of putting eight queens on an Chess |


He doesn't need to know the answer for every piece. Pawns seems rather uninteresting and he doesn't like Bishops anyway. He only wants to know how many Rooks, Knights, Queens or Kings can be placed on one board, such that one piece can't take any other.
Input
The first line of input contains the number of problems. A problem is stated on one line and consists of one character from the following set r, k, Q, K, meaning respectively the chesspieces Rook, Knight, Queen or King. The character is followed by the integers m (

Output
For each problem specification in the input your program should output the maximum number of chesspieces which can be put on a board with the given formats so they are not in position to take any other piece.Note: The bottom left square is 1, 1.
Sample Input
2 r 6 7 k 8 8
Sample Output
6 32
chess, no need to use DFS >"<
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define DBG 0
using namespace std;
int R,C,T,G;
bool tht[10][10];
int mp[128];
void init(){
mp['r']=0,mp['k']=1,mp['Q']=2,mp['K']=3;
}
void getNum(){
int ans;
if(T==3){R=R%2?R+1:R,C=C%2?C+1:C,printf("%d\n",R*C/4);return;}
if(T==1){ans=R*C/2,printf("%d\n",ans);return;}
if(T==0||T==2){printf("%d\n",G);return;}
}
int main(){
int a,b,c;
string s;
cin>>a;
init();
rep(i,a){
cin>>s>>R>>C;
G=min(R,C);
if(DBG)printf("R C %d %d\n",R,C);
T=mp[s[0]];
getNum();
}
}
沒有留言:
張貼留言