UVA 696 How Many Knights

真心没发现规律。感觉挺像CF一些锻炼思维的题

看了这里http://hi.baidu.com/knowledgetime/item/87d13b1f12290a53f1090ea7

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
int N,M;
int slove()
{
    if (N == 1 || M == 1)  return max(N,M);
    else if (N == 2 || M == 2)
    {
        if (M > N) swap(N,M);// N>M;right now M == 2;
        int cnt = N / 4 * 4;
        if (N % 4 == 1 || N % 4 == 2 ) cnt += N % 4 * 2;
        else if (N % 4 == 3) cnt += 4;
        return cnt;
    }
    else return ((M * N) + 1) / 2;
}
int main()
{
    while (scanf("%d%d",&N,&M)!=EOF)
    {
        if (N == 0 && M == 0) break;
        int u = N , v = M;
        printf("%d knights may be placed on a %d row %d column board.\n",slove(),u,v);
    }
    return 0;
}

 

posted @ 2014-09-25 23:46  Commence  阅读(188)  评论(0编辑  收藏  举报