Onlyot
OnlyotDN
2018-09-19 13:07

请问能帮我看一下UVA297一题中我的答案吗?

  • 算法
  • uva

UVA297题目
我的答案一直WA,有大佬能帮忙看一下吗?谢谢!
样例 和 udebug上的都是可以通过的。

 #include <bits/stdc++.h>
#include <iostream>
using namespace std;

const int maxn = 1024;
const int len = 32;
int buf[len][len];
char s[maxn];

void solve(int& p,int x, int y,int size) {
    char ch = s[p++];
    if (ch == 'p') {
        solve(p, x, y, size / 2);
        solve(p, x, y - size / 2, size / 2);
        solve(p, x + size / 2, y - size / 2, size / 2);
        solve(p, x + size / 2, y, size / 2);
    }
    else if(ch == 'f') {

        for (int i = x; i < x + size; i++)
            for (int j = y; j > y - size; j--)
                buf[i][j] = 1;
    }
}
int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        memset(buf, 0, sizeof(buf));
        for (int i = 0; i < 2; i++) {
            scanf("%s", s);

            int size = len;
            int x = 0, y = 31;
            int p = 0;
            solve(p, x, y, size);
        }

        int sum = 0;
        for (int i = 0; i < len; i++)
            for (int j = 0; j < len; j++)
                sum += buf[i][j];
        printf("There are %d black pixels.\n", sum);
    }
    return 0;
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答