Poj Solution 1323

http://poj.org/problem?id=1323

#include<iostream>
#include<algorithm>
using namespace std;
const int mMax = 22;
const int nMax = 52;
 
struct data{
    int num;
    bool my;
    bool small;
}card[mMax * nMax];
 
int main(){
    int m , n, i, j, t = 1;
    while(cin >> m >> n && m != 0){
        for(i = 1; i <= m * n; i ++){
            card[i].num = i;
            card[i].my = false;
            card[i].small = false;
        }
        for(i = 1; i <= n; i ++){
            int number;
            cin >> number;
            card[number].my = true;
        }
        getchar();
        getchar();

        int ans = n;
        for(i = m * n; i >= 2 && ans > 0; i --)
            if(!card[i].my)
                for(j = i - 1; j >= 1; j --)
                    if(card[j].my && !card[j].small){
                        card[j].small = true;
                        ans --;
                        break;
                    }
        cout << "Case " << t++ << ": " << ans << endl;
    }
    return 0;
}
											
This entry was posted in poj. Bookmark the permalink.