アルゴリズム

0122 - Summer of Phyonkichi

#include <iostream> #include <queue> #include <string> using namespace std; const int dx[12]={2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2}; const int dy[12]={0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -1}; struct DATA { int x, y, number; DATA(int a, int b, int c) {x=a; y=b;</string></queue></iostream>…

0121 - Seven Puzzle

#include <iostream> #include <map> #include <queue> #include <string> #include <utility> using namespace std; const int d[4]={-1, 1, -4, 4}; map<string,int> count; void bfs(void) { queue<string> que; que.push("01234567"); while ( !que.empty() ) { string wk1=que.front(); que.pop(); int pos=wk1.find</string></string,int></utility></string></queue></map></iostream>…

0118 - Property Distribution

#include <iostream> #include <string> using namespace std; int H, W; string field[100]; void dfs(int i, int j, char fruit) { field[i][j]='.'; if (j+1</string></iostream>

0117 - A reward for a Carpenter

#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <queue> #include <vector> #include <utility> using namespace std; #define MAX_V 20 #define INF (1<<29) typedef pair<int,int> P_II; struct edge { int to, cost; edge(int a, int b) {to=a; cost=b;} }; vector<edge> …</edge></int,int></utility></vector></queue></iostream></functional></cstdio></algorithm>

0093 - Leap Year

#include <iostream> using namespace std; bool Leap_Year(int year) { return ( ( !(year%400) || (!(year%4) && year%100) )? true : false ); } void Slove(int a, int b) { bool flg=false; for (int year=a; year<=b; ++year) if ( Leap_Year(year) ) { flg=true</iostream>…

0092 - Square Searching

#include <algorithm> #include <iostream> using namespace std; int dp[1000+1][1000+1]; void Init(int n) { for (int i=0; i<=n; ++i) for (int j=0; j<=n; ++j) dp[i][j]=0; } void Slove(int n) { int answer=0; char field[n+1][n+1]; Init(n); for (int i=1; i<=n; ++i) f</iostream></algorithm>…

0072 - Carden Lantern

#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; #define MAX_N 100 typedef pair<int,int> P_II; vector<P_II> G[MAX_N]; void Prim(int n) { int answer=0; bool used[n]; priority_queue< P_II,vector<…</p_ii></int,int></vector></utility></queue></iostream></functional></cstdio></algorithm>

0071 - Bombs Chain

#include <iostream> using namespace std; bool flg[8][8]; void dfs(int x, int y) { flg[y][x]=false; for (int k=1; k<=3; ++k) { if (flg[y][x+k] && x+k<8) dfs(x+k,y); if (flg[y+k][x] && y+k<8) dfs(x,y+k); if (flg[y][x-k] && 0<=x-k) dfs(x-k,y); if (flg[</iostream>…

0067 - The Number of Island

#include <iostream> #include <string> using namespace std; void dfs(string data[], int i, int j) { data[i][j]='0'; if (j<12-1 && data[i][j+1]=='1') dfs(data,i,j+1); if (i<12-1 && data[i+1][j]=='1') dfs(data,i+1,j); if (0</string></iostream>

0043 - Puzzle

#include <iostream> #include <string> using namespace std; int Check(int number[]) { int sum=0; for (int i=1; i<10; ++i) sum+=number[i]; return sum; } void dfs(int number[], bool answer_flg[], int i) { if ( !Check(number) ) answer_flg[i]=true; else { for (i</string></iostream>…

0042 - A Thief

#include <cstdio> #include <iostream> using namespace std; int dp[1000+1][1000+1]; int Slove(int W, int number) { int N, value[1000], weight[1000], value_max=0, weight_max=0; cin >> N; for (int i=0; i<=N; ++i) for (int j=0; j<=W; ++j) dp[i][j]=0; for (int i</iostream></cstdio>…

0033 - Ball

#include <iostream> using namespace std; bool flg; void dfs(int A[], int B, int C, int count) { if (count == 10) flg=true; else { if (B==0 && C==0) { dfs(A,A[count],C,count+1); dfs(A,B,A[count],count+1); } else { if (A[count] > B) dfs(A,A[count],C,c</iostream>…

0030 - Sum of Integers

#include <iostream> using namespace std; int n, s, answer; void dfs(int number, int sum, int count) { if (n==count && s==sum) ++answer; if (number==10 || n==count) return; dfs(number+1,sum,count); dfs(number+1,sum+number,count+1); } void Slove(void)</iostream>…

0027 - What day is today?

#include <iostream> using namespace std; int Zeller(int year, int month, int day) { if (month==1 || month==2) { --year; month+=12; } return (year+year/4-year/100+year/400+(13*month+8)/5+day)%7; } void Slove(int month, int day) { string date[7]={"Sun</iostream>…