模擬·The Archaeologist's Trouble II ·ZOJ 2058

題目大意:

稍微一看就能知道是說*和@在一排中不能相鄰,所以只需要間隔擺放就行;

我WA了三次就是有一句:

The input is terminated by a negative integer.

我沒看見,我的處理是 != -1。

AC代碼:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;
//#define   maxd          1010
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define   mc(x, y)     memcpy(x, y, sizeof(x))
#define   ms(x,y)      memset(x,y,sizeof(x))
#define   rep(i,n)      for(int i=0;i<(n);i++)
#define   repf(i,a,b)   for(int i=(a);i<=(b);i++)
#define   PI           pair<int,int>
//#define   mapp            make_pair
#define   FI            first
#define   SE            second
#define   IT            iterator
#define   PB            push_back
#define   Times         10
typedef   long long     ll;
typedef   unsigned long long ull;
typedef   long double   ld;
typedef   pair<int,int > pce;
//#define N 100
const double eps = 1e-10;
const double  pi = acos(-1.0);
const  ll    mod = 1e9+7;
const  int   inf = 0x3f3f3f3f;
//const  ll    INF = (ll)1e18+300;
const int   maxd = 100000 + 10;
const int   maxx = 10100;

char tower[1010][1010];
char ac[1010][1010];
int vis[1010];
int main() {
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n) {
        if(n < 0) {
            break;
        }
        ms(vis, 0);
        ms(tower, 0);
        ms(ac, 0);
        int ans_1 = 0;
        int ans_2 = 0;
        for (int i = 1; i <= n; i++) {
            int flag = 1;
            for (int j = 1; j <= i; j++) {
                cin >> tower[i][j];
                if(tower[i][j] != '?') {
                    flag = 0;
                }
                if(tower[i][j] == '@') {
                    ans_1 ++;
                }
            }
            if(flag) {
                vis[i] = 1;
            }
        }
        ans_2 = ans_1;
        mc(ac, tower);
        /*求最多,填充@多一些*/
        for (int i = 1; i <= n; i++) {
            if(vis[i]) {
                //cout << "+++ " << i << " " << i/2 << endl;
                if(i == 1) {
                    ans_1 ++;
                    continue;
                }
                if(i % 2 == 0){
                    ans_1 += i/2;
                }
                else {
                    ans_1 += i/2;
                    ans_1 ++;
                }
            }
            else {
                int pos;
                for (int j = 1; j <= n; j++) {
                    if(tower[i][j] != '?') {
                        pos = j;
                        break;
                    }
                }
                for (int j = pos-1; j >= 1; j--) {
                    if(tower[i][j] != '?') {
                        continue;
                    }
                    if(tower[i][j + 1] == '*') {
                        tower[i][j] = '@';
                        ans_1 ++;
                    }
                    else {
                        tower[i][j] = '*';
                    }
                }
                for (int j = pos + 1; j <= i; j++) {
                    if(tower[i][j] != '?') {
                        continue;
                    }
                    if(tower[i][j - 1] == '*') {
                        tower[i][j] = '@';
                        ans_1 ++;
                    }
                    else {
                        tower[i][j] = '*';
                    }
                }
            }
        }
        /*求最少就是填充*多一些
         */
        for (int i = 1; i <= n; i++) {
            if(vis[i]) {
                //cout << "+++ " << i << " " << i/2 << endl;
                ans_2 += i/2;
            }
            else {
                int pos;
                for (int j = 1; j <= n; j++) {
                    if(ac[i][j] != '?') {
                        pos = j;
                        break;
                    }
                }
                for (int j = pos-1; j >= 1; j--) {
                    if(ac[i][j] != '?') {
                        continue;
                    }
                    if(ac[i][j + 1] == '*') {
                        ac[i][j] = '@';
                        ans_2 ++;
                    }
                    else {
                        ac[i][j] = '*';
                    }
                }
                for (int j = pos + 1; j <= i; j++) {
                    if(ac[i][j] != '?') {
                        continue;
                    }
                    if(ac[i][j - 1] == '*') {
                        ac[i][j] = '@';
                        ans_2 ++;
                    }
                    else {
                        ac[i][j] = '*';
                    }
                }
            }
        }

//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= i; j++) {
//                cout << ac[i][j] << " ";
//            }cout << endl;
//        }
        cout << ans_1 << " " << ans_2 << endl;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章