#include<stdio.h>
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define ll long long
#define Max(a,b) (a>b?a:b)
int x[]= {-1,0,-1,0,1,1};
int y[] = {0,1,-1,-1,0,1};
char str[201][201];
bool visited[201][201];
int row ;
bool black ;
void dfs(int r,int c)
{
if(r == 0) black =true ;
for(int i=0; i<6; i++)
{
int R = r+x[i];
int C = c+y[i];
if(R>=0 && R<row && C>=0 && C<row && visited[R][C]==false&&str[R][C]=='b')
{
visited[R][C] =true ;
dfs(R,C);
}
}
}
void init()
{
for(int i=0; i<201; i++)
for(int j=0; j<201; j++) visited[i][j]= false ;
black=false;
}
int main()
{
// READ ;
int cnt = 0 ;
while(scanf("%d",&row)==1 && row!=0)
{
init() ;
for(int i = 0; i< row ; i++) scanf("%s",str[i]);
for(int i=0; i<row; i++)
{
if(str[row-1][i]=='b')
{
dfs(row-1,i);
}
}
if(black)printf("%d %c\n",++cnt,'B');
else printf("%d %c\n",++cnt,'W');
}
return 0 ;
}
About Me
About Me :
I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).
Skills
Skills
• Javascript •Typescript •Python •C •Java
•ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs
• Git • Docker • Jira • Visual Studio Code • Slack
সোমবার, ২১ আগস্ট, ২০১৭
uva 260 solution
বৃহস্পতিবার, ১৭ আগস্ট, ২০১৭
UVA 167
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define READ freopen("input.txt","r",stdin)
#define ll long long
int ary[9][9];
int chk[9][9];
int mx ;
int MAX(int a,int b)
{
return a>b?a:b;
}
bool issafe(int row,int col)
{
for(int i=0;i<8;i++)
{
if(chk[row][i]==1) return false ;
}
for(int i=0;i<=row;i++)
if(chk[i][col]==1) return false;
for(int i=row,j=col;i>=0 && j>=0;i--,j--)
{
if(chk[i][j]==1) return false;
}
for(int i=row,j=col;i>=0&& j<8;i--,j++)
{
if(chk[i][j]==1) return false;
}
return true;
}
void NQ(int r,int sum)
{
if(r==8)
{
mx = MAX(mx,sum);
return ;
}
for(int c = 0; c<8; c++)
{
if(issafe(r,c))
{
chk[r][c] =1;
NQ(r+1,sum+ary[r][c]);
chk[r][c] =0;
}
}
}
int main()
{
READ ;
int test ;
scanf("%d",&test);
while(test--)
{
for(int i=0; i<8; i++)
{
for(int j=0; j<8; j++) scanf("%d",&ary[i][j]);
}
mx = -1 ;
//clear();
NQ(0,0);
printf("%5d\n",mx);
}
return 0;
}
#include<math.h>
#include<stdlib.h>
#define READ freopen("input.txt","r",stdin)
#define ll long long
int ary[9][9];
int chk[9][9];
int mx ;
int MAX(int a,int b)
{
return a>b?a:b;
}
bool issafe(int row,int col)
{
for(int i=0;i<8;i++)
{
if(chk[row][i]==1) return false ;
}
for(int i=0;i<=row;i++)
if(chk[i][col]==1) return false;
for(int i=row,j=col;i>=0 && j>=0;i--,j--)
{
if(chk[i][j]==1) return false;
}
for(int i=row,j=col;i>=0&& j<8;i--,j++)
{
if(chk[i][j]==1) return false;
}
return true;
}
void NQ(int r,int sum)
{
if(r==8)
{
mx = MAX(mx,sum);
return ;
}
for(int c = 0; c<8; c++)
{
if(issafe(r,c))
{
chk[r][c] =1;
NQ(r+1,sum+ary[r][c]);
chk[r][c] =0;
}
}
}
int main()
{
READ ;
int test ;
scanf("%d",&test);
while(test--)
{
for(int i=0; i<8; i++)
{
for(int j=0; j<8; j++) scanf("%d",&ary[i][j]);
}
mx = -1 ;
//clear();
NQ(0,0);
printf("%5d\n",mx);
}
return 0;
}
সোমবার, ১৪ আগস্ট, ২০১৭
UVA 280 SOLUTION
#include<stdio.h>
#define READ freopen("Text.txt","r",stdin)
#define ll long long
#define READ freopen("Text.txt","r",stdin)
#define ll long long
int node;
int graph[102][102];
int visited[102];
int graph[102][102];
int visited[102];
void clear(int node)
{
for (int i = 0; i <= node; i++) visited[i] = 0;
{
for (int i = 0; i <= node; i++) visited[i] = 0;
}
void init_Graph()
{
for (int i = 0; i < 101; i++)
for (int j = 0; j < 102; j++) graph[i][j] = 0;
}
void dfs(int n)
{
for (int i = 1; i <= node; i++)
{
if (graph[n][i] == 1 && visited[i] == 0)
{
visited[i] = 1;
dfs(i);
}
}
{
for (int i = 0; i < 101; i++)
for (int j = 0; j < 102; j++) graph[i][j] = 0;
}
void dfs(int n)
{
for (int i = 1; i <= node; i++)
{
if (graph[n][i] == 1 && visited[i] == 0)
{
visited[i] = 1;
dfs(i);
}
}
return;
}
int main()
{
// READ;
while (scanf("%d", &node) == 1 && node != 0)
{
int start, n, q, s;
init_Graph();
while (scanf("%d", &start) == 1 && start != 0)
{
while (scanf("%d", &n) && n != 0)
{
graph[start][n] = 1;
}
}
scanf("%d", &q);
while (q--)
{
scanf("%d", &s);
int ans = 0;
clear(node);
dfs(s);
for (int i = 1; i <= node; i++) if (visited[i] == 0) ans++;
printf("%d", ans);
for (int i = 1; i <= node; i++) if (visited[i] == 0) printf(" %d", i);
puts("");
}
int main()
{
// READ;
while (scanf("%d", &node) == 1 && node != 0)
{
int start, n, q, s;
init_Graph();
while (scanf("%d", &start) == 1 && start != 0)
{
while (scanf("%d", &n) && n != 0)
{
graph[start][n] = 1;
}
}
scanf("%d", &q);
while (q--)
{
scanf("%d", &s);
int ans = 0;
clear(node);
dfs(s);
for (int i = 1; i <= node; i++) if (visited[i] == 0) ans++;
printf("%d", ans);
for (int i = 1; i <= node; i++) if (visited[i] == 0) printf(" %d", i);
puts("");
}
}
return 0;
}
}
uva 118 solution
#include<stdio.h>
#define ll long long
int row, col;
int ary[100][100];
char d[10], str[102];
int main()
{
//freopen("Text.txt", "r", stdin);
scanf("%d %d", &row, &col);
for (int i = 0; i <= row; i++)
for (int j = 0; j <= col; j++) ary[i][j] = 0;
int r, c;
while (scanf("%d %d %s", &r, &c, d) == 3)
{
scanf("%s", str);
char dir = d[0];
bool flag = true;
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] == 'R' || str[i] == 'L')
{
//printf("%d\n",i+1);
if (dir == 'E')
{
str[i] == 'R' ? dir = 'S' : dir = 'N';
}
else if (dir == 'N')
{
str[i] == 'R' ? dir = 'E' : dir = 'W';
}
else if (dir == 'S')
{
str[i] == 'R' ? dir = 'W' : dir = 'E';
}
else
{
str[i] == 'R' ? dir = 'N' : dir = 'S';
}
//printf("---%c----", dir);
}
else
{
if (dir == 'E')
{
if (r + 1 <= row) r += 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
if (dir == 'N')
{
if (c + 1 <= col) c += 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
if (dir == 'S')
{
if (c - 1 >= 0) c -= 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
if (dir == 'W')
{
if (r - 1 >= 0) r -= 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
//printf("%d %d\n", r, c);
}
// printf("%c\n",dir);
}
if (flag) printf("%d %d %c\n", r, c, dir);
}
return 0;
}
#define ll long long
int row, col;
int ary[100][100];
char d[10], str[102];
int main()
{
//freopen("Text.txt", "r", stdin);
scanf("%d %d", &row, &col);
for (int i = 0; i <= row; i++)
for (int j = 0; j <= col; j++) ary[i][j] = 0;
int r, c;
while (scanf("%d %d %s", &r, &c, d) == 3)
{
scanf("%s", str);
char dir = d[0];
bool flag = true;
for (int i = 0; str[i] != '\0'; i++)
{
if (str[i] == 'R' || str[i] == 'L')
{
//printf("%d\n",i+1);
if (dir == 'E')
{
str[i] == 'R' ? dir = 'S' : dir = 'N';
}
else if (dir == 'N')
{
str[i] == 'R' ? dir = 'E' : dir = 'W';
}
else if (dir == 'S')
{
str[i] == 'R' ? dir = 'W' : dir = 'E';
}
else
{
str[i] == 'R' ? dir = 'N' : dir = 'S';
}
//printf("---%c----", dir);
}
else
{
if (dir == 'E')
{
if (r + 1 <= row) r += 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
if (dir == 'N')
{
if (c + 1 <= col) c += 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
if (dir == 'S')
{
if (c - 1 >= 0) c -= 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
if (dir == 'W')
{
if (r - 1 >= 0) r -= 1;
else
{
if (ary[r][c] == 0)
{
ary[r][c] = 1;
printf("%d %d %c LOST\n", r, c, dir);
flag = false;
break;
}
else continue;
}
}
//printf("%d %d\n", r, c);
}
// printf("%c\n",dir);
}
if (flag) printf("%d %d %c\n", r, c, dir);
}
return 0;
}
রবিবার, ১৩ আগস্ট, ২০১৭
uva 11003 solution
#include<stdio.h>
#define ll long long
int N;
int weight[1003], load[1003];
int weight1[1003], load1[1003];
int dp[1005][9002];
void clear()
{
for (int i = 0; i < 1001; i++)
for (int j = 0; j < 9001; j++) dp[i][j] = -1;
}
int Max(int a, int b)
{
return a > b ? a : b;
}
int solve(int i, int w)
{
if (dp[i][w] != -1) return dp[i][w];
if (i >=N) return 0;
int a = 0, b = 0;
if (w <= load[i])
{
a = 1 + solve(i + 1, w + weight[i]);
}
b = solve(i + 1, w);
return dp[i][w]=Max(a, b);
//return Max(a, b);
}
int main()
{
// freopen("Text.txt", "r", stdin);
while (scanf("%d", &N) == 1 && N != 0)
{
for (int i = 0; i < N; i++) scanf("%d %d", &weight1[i], &load1[i]);
for (int i = 0, j = N - 1; i < N; i++, j--) weight[i] = weight1[j], load[i] = load1[j];
clear();
int ans = solve(0, 0);
printf("%d\n", ans);
}
return 0;
}
#define ll long long
int N;
int weight[1003], load[1003];
int weight1[1003], load1[1003];
int dp[1005][9002];
void clear()
{
for (int i = 0; i < 1001; i++)
for (int j = 0; j < 9001; j++) dp[i][j] = -1;
}
int Max(int a, int b)
{
return a > b ? a : b;
}
int solve(int i, int w)
{
if (dp[i][w] != -1) return dp[i][w];
if (i >=N) return 0;
int a = 0, b = 0;
if (w <= load[i])
{
a = 1 + solve(i + 1, w + weight[i]);
}
b = solve(i + 1, w);
return dp[i][w]=Max(a, b);
//return Max(a, b);
}
int main()
{
// freopen("Text.txt", "r", stdin);
while (scanf("%d", &N) == 1 && N != 0)
{
for (int i = 0; i < N; i++) scanf("%d %d", &weight1[i], &load1[i]);
for (int i = 0, j = N - 1; i < N; i++, j--) weight[i] = weight1[j], load[i] = load1[j];
clear();
int ans = solve(0, 0);
printf("%d\n", ans);
}
return 0;
}
এতে সদস্যতা:
পোস্টগুলি (Atom)