라벨이 Topcoder_Srm인 게시물 표시

(SRM691) PlusOneGame(div2_300)

//각 숫자에 해당하는 인덱스의 배열을 만들고 해당 숫자가 나오는 갯수 만큼 횟수를 증가시켰다. 그런 후 출력시 그 갯수만큼 숫자를 출력하였다. +는 현재 숫자가 존재하는지 유무와 관계없이 i루프를 돌면서 계속 추가시켰다 또한 string t; t=t+'+' 를 하면 현재 문자열 맨 앞에 해당 '+'가 추가 되는 것을 명심하자 #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<string> #include<bits/stdc++.h> using namespace std; class Plusonegame{ public: int cal[20]; public: string getorder(string s){ int n = s.size(); memset(cal, 0, sizeof(cal)); int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == '+')cnt++; else cal[s[i] - '0']++; } string ans; for (int i = 0; i <= 9; i++) { for (int j = 0; j < cal[i]; j++)ans = ans + char(i + '0'); if (cnt){ ans = ans + '+'; cnt--; } } while (cnt){ ans = ans + '+'; cnt--; } return ans; } };

(Topcoder)TCC algorithm Round 4 Chess Metric

public class ChessMetric { private static int[] dx=new int[]{1,-1,0,0,1,-1,-1,1,2,-2,2,-2,1,1,-1,-1};         private static int[] dy=new int[]{0,0,-1,1,1,-1,1,-1,1,1,-1,-1,2,-2,2,-2};         private static int dp[][]; public static long howMany(int size,int[] start,int[] end,int numMoves){ dp=new int[size][size]; for(int[] row:dp) Arrays.fill(row, -1); int x=start[0]; int y=start[1]; int ret=0; for(int i=0;i<16;i++) { ret=Math.max(ret,move(x+dx[i],y+dy[i],end,numMoves)); } return ret; } private static int move(int x,int y,int[] end,int numMoves) { if(x<0 || y<0 || x>=dp.length ||y >=dp.length) return 0; if(x==end[0] && y==end[1] && numMoves==0)return 1; if(numMoves<0)return 0; if(dp[x][y]!=-1)return dp[x][y]; int ret=0; for(int i=0;i<16;i++){ ret+=move(x+dx[i],y+dy[i],end,numMoves--); } return dp[x][y]=re...

(Topcoder)TCO algorithm 2016 500pt

이 문제의 의문점 5중배열의 선언이 이해가 가질 않았다. [A][B][C][이전 꺼][이 전전꺼] -->>>>A,B,C는 현재위치에 해당하는 A,B,C이며 이전과 이전전에 따라 구분되기 때문에 5중배열이 선언되었다. public class ThreeProgrammers { public static void main(String[] args) { // TODO Auto-generated method stub String a="BB"; System.out.println(validCodeHistory(a)); } public static String validCodeHistory(String code) { int a=0,b=0,c=0; for(int i=0;i<code.length();i++) { if(code.charAt(i)=='A')a++; else if(code.charAt(i)=='B')b++; else c++; } String bad="impossible"; String[][][][][] dp=new String[a+1][b+1][c+1][3][3]; if(a>0){ dp[1][0][0][0][0]="A"; } if(b>0) dp[0][1][0][1][0]="B"; if(c>0) dp[0][0][1][2][0]="C"; int i,j,k,w,e; for(i=0;i<=a;i++){ for(j=0;j<=b;j++){ for(k=0;k<=c;k++){ for(w=0;w<3;w++){ for(e=0;e<3;e++){ if(dp[i][j][k][w][e]...

(Topcoder) SRM689-div2 1000

ll bits = ( ll ) __builtin_popcount ( mask ) ; 현재 mask의 비트가 1인 것들의 위치를 반환 하는 것을 _builtin_popcount()이다.

Topcoder-SRM689 div2 500

Problem Statement      You are given two Strings: A and B . Each character in A is either '0' or '1'. Each character in B is '0', '1', or '?'. A string C matches B if we can change B into C by changing each '?' in B either to '0' or to '1'. Different occurrences of '?' may be changed to different digits. For example, C = "0101" matches B = "01??". Note that each character in C must be either '0' or '1', there cannot be any '?' remaining. Consider all possible strings that match B . How many of these strings occur as a (contiguous) substring in A ? Compute and return their number. Note that we only count each good string once, even if it has multiple occurrences in A 접근 방법: ...