Click on table to read problem, discuss, debug !
Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
| discuss278 - | Accepted | C++11 | 0.000 | 0.000 | 2989 | 10 mins ago |
Suggest:
Rook : it's easy to see that the best way to place pieces is on the diagonal
Queen: by relying on the classic problem that the problem mentioned, we can google it and find out that although the way is different, the result is still the same as the rook.
King: just placing the pieces one square apart is optimal
Knight: this is the most troublesome piece, after a while of trying several cases I finally realized the optimal way to place it is to place it alternately as shown below
#include<bits/stdc++.h>
using namespace std;
int t, n, m;
char k;
int knight(int n, int m){
if (n < m) swap(n, m);
if (n%2)
return (n/2+n%2)*(m/2+m%2) + (n/2)*(m/2);
return n/2*m;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> t;
while(t--){
cin >> k >> n >> m;
if (k=='r' || k=='Q')
cout << min(n, m);
else
if (k=='K')
cout << (m/2+m%2)*(n/2+n%2);
else
cout<< knight(n, m);
cout<<"\n";
}
}
No comments:
Post a Comment