Thursday, November 4, 2010

ACM - UVA 278 - Chess

Problem: 278 - Chess
Solution:C++
Hints: http://www.algorithmist.com/index.php/UVa_278

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
using namespace std;

int min(int a, int b)
{
    if(a < b)
    {
        return a;
    }
    return b;
}
  

int main()
{
     char sor[100];
     int x, y, n;
     char b;
     scanf("%d",&n);
     gets(sor);
     while(n--) 
    {
        gets(sor);
        sscanf(sor,"%c %d %d",&b,&x,&y);
        switch(b)
        {
            case 'r' :
                printf("%d\n",min(x,y));
                break;
            case 'Q' :
                printf("%d\n",min(x,y));
                break;
            case 'k' :
                printf("%d\n",((x*y)+1)/2);
                break;

            case 'K' :
                printf("%d\n",((y+1)/2)*((x+1)/2));
                break;
        }
    }
    return 0;
}



       

No comments:

Post a Comment