SRM 477 :: 2010/07/29 23:00

어제 밤 12시에 열린 매치..~





Level1 - Islands

더보기


그림과같이 정육각형 모양으로 생긴 지도를 input 으로 나올때, 해변의 길이 구하기..

모든 '#' 에 대해서 주위가 '.' 인지 아닌지를 검사하면 된다..~

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <algorithm>
  4 #include <vector>
  5 #include <string>
  6 using namespace std;
  7 //#define min(x, y) ((x) > (y) ? (y) : (x))
  8 //#define max(x, y) ((x) > (y) ? (x) : (y))
  9 //#define INF 999999999
 10 //#define EPS 1e-14
 11
 12 class Islands {
 13 public:
 14
 15 int beachLength(vector <string> kingdom)
 16 {
 17     int r, c;
 18     int cnt;
 19     int i, j;
 20     r = kingdom.size();
 21     c = kingdom[0].size();
 22     cnt = 0;
 23     for (i = 0; i < r; i++) {
 24         for (j = 0; j < c; j++) {
 25             if (kingdom[i][j] == '#') {
 26                 if (j-1 >= 0 && kingdom[i][j-1] == '.') {
 27                     cnt++;
 28                 }
 29                 if (j+1 < c && kingdom[i][j+1] == '.') {
 30                     cnt++;
 31                 }
 32                 if (i % 2 == 0) {
 33                     if (i+1 < r && j-1 >= 0 && kingdom[i+1][j-1] == '.') {
 34                         cnt++;
 35                     }
 36                     if (i+1 < r && j >= 0 && kingdom[i+1][j] == '.') {
 37                         cnt++;
 38                     }
 39                     if (i-1 >= 0 && j-1 >= 0 && kingdom[i-1][j-1] == '.') {
 40                         cnt++;
 41                     }
 42                     if (i-1 >= 0 && j >= 0 && kingdom[i-1][j] == '.') {
 43                         cnt++;
 44                     }
 45                 }
 46                 else {
 47                     if (i+1 < r && j+1 < c && kingdom[i+1][j+1] == '.') {
 48                         cnt++;
 49                     }
 50                     if (i+1 < r && j < c && kingdom[i+1][j] == '.') {
 51                         cnt++;
 52                     }
 53                     if (i-1 >= 0 && j+1 < c && kingdom[i-1][j+1] == '.') {
 54                         cnt++;
 55                     }
 56                     if (i-1 >= 0 && j < c && kingdom[i-1][j] == '.') {
 57                         cnt++;
 58                     }
 59                 }
 60             }
 61         }
 62     }
 63 printf("cnt = %d\n", cnt);
 64     return cnt;
 65 }
 66
 67 };



Level2 - PythTriplets

더보기


주어진 input 에서 x^2 + y^2 = z^2  을 만족하는 (x, y) pair 를 최대한 많이 찾기..~


to be updated..



Level3 - KingdomTour

더보기



to be updated..


'Problem Solving > TopCoder logs' 카테고리의 다른 글

SRM 477  (0) 2010/07/29
SRM 476 - GOOD  (0) 2010/07/20
SRM 472 - 현충일 새벽에 삽질..  (0) 2010/06/07
SRM 470  (0) 2010/05/28
TCO10 Qual3 - 이런 젠장  (0) 2010/05/25
TCO10 Qaul2  (2) 2010/05/13
Trackback Address :: http://apnetwork.tistory.com/trackback/372 관련글 쓰기
Name
Password
Homepage
Secret
< PREV #1 #2 #3 #4 #5 ... #358  | NEXT >