codeforces 192 c

July 22, 2013
CodeForces

link: http://codeforces.com/contest/330/problem/C broute force  but you must be careful about some tricks and think about all the instances


/*
ID: zypz4571
LANG: C++
TASK: 192c.cpp
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>

#define INF 0x3f3f3f3f
#define REP(i, n) for(int i=0;i<int(n);++i)
#define FOR(i, a, b) for(int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for(int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for(int i=1;i<=int(n);++i)
#define mid int m=(l+r)/2
using namespace std;
int a[102][102], rows[102], cols[102];
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
    int n; cin>>n;
    char ch;
    getchar();
    REP(i, n) {
        REP(j, n) {
            scanf("%c", &ch);
            if (ch == '.') a[i][j] = 1;
            else a[i][j] = 0;
        }
        getchar();
    }
    bool flaga = true, flagb = true;
    vector<pair<int, int> > v;
//    REP(i, n) {                                 /*here is error */
//        flag = false;                             /* can not judge like this */
//        REP(j, n) {                               /* short of some instance */
//            if (a[i][j] == 1) {
//                v.push_back(make_pair(i+1,j+1)); flag = true;
//                break;
//            }
//        }
//        if (!flag) break;
//    }
    REP(i, n) {
        REP(j, n) {
            rows[i] += a[i][j]; 
            cols[j] += a[i][j];
        }
    }
    REP(i, n) {
        if (!rows[i]) flaga = false;
        if (!cols[i]) flagb = false;
    }
    if (!flaga && !flagb) cout<<"-1"<<endl;
    else {
        if (!flagb)
        REP(i, n) {
            REP(j, n) {
                if (a[i][j] == 1) {v.push_back(make_pair(i+1, j+1)); break;}
            }
        }
        else 
        REP(j, n) {
            REP(i, n) {
                if (a[i][j] == 1) {v.push_back(make_pair(i+1, j+1)); break;}
            }
        }
        vector<pair<int, int> >::iterator it;
        for (it = v.begin(); it != v.end(); ++it) {
            cout << (*it).first<<' '<<(*it).second<<endl;
        }
    }
        return EXIT_SUCCESS;
}                /* ----------  end of function main  ---------- */

I got a WA in the match. sad…..

comments powered by Disqus