Code: Select all
omg thank you so much! super silly mistakes...
Moderator: Board moderators
Code: Select all
omg thank you so much! super silly mistakes...
Code: Select all
cout << "Case " << counter++ << ": " << ans;
Code: Select all
cout << "Case " << counter++ << ": " << ans << "\n";
Code: Select all
Removed After ACC
Code: Select all
#include<stdio.h>
long B[109][109],n,cas,cas1,count,i,j;
char A[109][109];
void make(long x,long y,long z,long z1)
{
B[x][y]=1;
if(z+1<=n/2)
{
if((z1==0 ||z1==1)&&x-1>=0&&('x'==A[x-1][y]||'@'==A[x-1][y])&&B[x-1][y]==0)
make(x-1,y,z+1,1);
else if((z1==0 ||z1==1)&&x+1<n&&('x'==A[x+1][y]||'@'==A[x+1][y])&&B[x+1][y]==0)
make(x+1,y,z+1,1);
else if((z1==0 ||z1==2)&&y-1>=0&&('x'==A[x][y-1]||'@'==A[x][y-1])&&B[x][y-1]==0)
make(x,y-1,z+1,2);
else if((z1==0 ||z1==2)&&y+1<n&&('x'==A[x][y+1]||'@'==A[x][y+1])&&B[x][y+1]==0)
make(x,y+1,z+1,2);
}
}
int main()
{
scanf("%ld",&cas);
for(cas1=1;cas1<=cas;cas1++)
{
scanf("%ld",&n);
for(i=0;i<n;i++)
{
scanf("%s",A[i]);
for(j=0;j<n;j++)
B[i][j]=0;
}
count = 0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(A[i][j]=='x'&&B[i][j]==0)
{
count++;
make(i,j,1,0);
}
printf("Case %ld: %ld\n",cas1,count);
}
return 0;
}
Code: Select all
AC
Code: Select all
1
3
x..
...
@.@
Code: Select all
Deleted After Ac :D
Code: Select all
1
5
x....
x....
.....
.....
.....
class Main{
static int[][] ar = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
static char[] temp;
static char[][] grid;
static int cnt;
static boolean alive;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t;
t = in.nextInt();
for (int k = 0; k < t; k++) {
int n = in.nextInt();
grid = new char[n + 2][n + 2];
cnt = 0;
in.nextLine();
for (int i = 0; i < n; i++) {
String line = in.nextLine();
temp = line.toCharArray();
for(int j=0;j<temp.length;j++){
grid[i+1][j+1]=temp[j];
}
}
for (int i = 1; i < grid.length - 1; i++) {
for (int j = 1; j < grid.length - 1; j++) {
if (grid[j] == 'x') {
cnt++;
dfs(i, j);
}
}
}
int ans = k + 1;
System.out.println("Case " + ans + ": " + cnt);
}
}
public static void dfs(int x, int y) {
if (x == (grid.length - 1) || y == (grid.length - 1) || x == 0 || y == 0 || grid[x][y] == '.') {
return;
}
grid[x][y] = '.';
for (int i = 0; i < ar.length; i++) {
int r = x + ar[0];
int c = x + ar[1];
dfs(r, c);
}
}
}
Code: Select all
for (int i = 0; i < ar.length; i++)
{
int r = x + ar[i][0];
int c = x + ar[i][1];
dfs(r, c);
}
Code: Select all
for (int i = 0; i < ar.length; i++)
{
int r = x + ar[i][0];
int c = y + ar[i][1];
dfs(r, c);
}
Code: Select all
enjoying life .....