[topcoder]SRM 633 DIV 2

第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076

模拟就可以了。

#include <vector>

#include <algorithm>



using namespace std;



class Target {

public:

  vector <string> draw(int n) {

    vector<string> result(n, string(n, ' '));

    int x = 0;

    int y = 0;

    while (n >= 1) {

      for (int i = 0; i < n; i++) {

        result[x + i][y] = '#';

        result[x][y + i] = '#';

        result[x + n - 1][y + i] = '#';

        result[x + i][y + n - 1] = '#';

      }

      x += 2;

      y += 2;

      n -= 4;

    }

    return result;

  }

};

第二题,想了很久。最后发现用三角形的A+B>=C,一个一个推,可以推出N条边所组成的多边形(开口)的距离范围。http://apps.topcoder.com/wiki/display/tc/SRM+633#Jumping

有详细的图示。

#include <vector>

#include <algorithm>

#include <string>

#include <algorithm>

using namespace std;



class Jumping {

public:

  string ableToGet(int x, int y, vector <int> jumpLengths) {

    double d = sqrt(1.0 * x * x + 1.0 * y * y);

    sort(jumpLengths.begin(), jumpLengths.end());

    double low = jumpLengths[0];

    double high = jumpLengths[0];

    for (int i = 1; i < jumpLengths.size(); i++) {

      low = max(0.0, jumpLengths[i] - high);

      high = high + jumpLengths[i];

    }

    if (d >= low && d <= high) {

      return "Able";

    } else {

      return "not able";

    }



  }



};

第三题,没做。后来看题解,就是用LCD和GCD的限制,得到x*y,然后穷举搜索。用DFS。

你可能感兴趣的:(topcoder)