problem with implementing this question of codechef

Pages: 1... 8910111213
please pm me
@MonkeyD

Can u discuss the algo to solve TWO Flowers for 20 points....
@needbro please pm your code i will try to rectify it....
I have passed subtask 1 but not subtask 2.. any possible errors? TIA
@noobiee how can we point out your errors without your algorithm.
@ wasp
have you solved two flowers problem
if yes please give me the idea of how to approach for this problem
thanks @mythio and @ak2614 for providing the needed help:)
hello guys
can anyone help me with the two flowers partial solution
please help me.
@texasgirl1234
refer connected cell problem hackerrank

@all

In two flower problem u can collect 1 and max. 2 flower from a cell and these should be in continous if adjacent to it are more than 2 flower than break from there so like this we have to counter the total no. Of cells not flowers from which we can collect flowers either 1 or 2.........
please someone help me rectify my output
giving wrong answer for original constraints

long double t,t1,t2;

if(X==0){
t=(-1*Z)/Y;
cout<<setprecision(12)<<t<<endl;
}
else{
t1=((-1*Y)+sqrt(Y*Y-(4*X*Z)))/(2*X);
t2=((-1*Y)-sqrt(Y*Y-(4*X*Z)))/(2*X);

if(t1>=0 && t2<0)cout<<setprecision(12)<<t1<<endl;
else if(t1<0 && t2>=0)cout<<setprecision(12)<<t2<<endl;
else if(t1>=0 && t2>=0)cout<<setprecision(12)<<min(t1,t2)<<endl;
}
#include <stdio.h>
#include<math.h>
int n,m,ct;
int a[100][100];
void check(int i,int j)
{
if(a[i][j]==0)
return;
a[i][j]=5;
ct++;
if(i+1<n&&a[i+1][j]==1 || a[i+1][j]==2){
check(i+1,j);

}
if(i-1>=0&&a[i-1][j]==1 || a[i-1][j]==2){
check(i-1,j);

}
if(j+1<m&&a[i][j+1]==1 || a[i][j+1]==2){
check(i,j+1);

}
if(j-1>=0&&a[i][j-1]==1 || a[i][j-1]==2){
check(i,j-1);

}

}
int main() {
while(scanf("%d%d",&n,&m)!=EOF)
{
int tt;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{tt=scanf("%d",&a[i][j]);}//printf("%d ",a[i][j]);}
//puts("");
}
//continue;
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]==1 || a[i][j]==2)
{
ct=0;
check(i,j);
if(ct>ans) ans=ct;
}
}
}
printf("%d\n",ans);
}
return 0;
}
Just passing 2 test case only.
@lastchance @Wase please see where I am getting wrong in 2 flowers problem
Any help would be appreciated
Last edited on
@yobro
Which question is it??
If it is vision one that this may be wrong if you have calculated the derived constants wrongly.
Try to post full code for review.
Last edited on
anyone can help for this problem.
Two Flowers Problem Code: TWOFL
its some kind of similar to this problem at hackerrank but problem is that in hackrank we consider diagonal (where cell 1 only) but in codechef we need only consider side adjecent of 1 or 2.
we can convert 1 and 2 to 1 and rest to Zero to make same as hackrank but how can i remove diagonal condition in problems in given code .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int m[100][100],t=2;

void region(int r,int c){
    
   m[r][c]=t;
    for(int i=r-1;i<=r+1;i++){
        for(int j=c-1;j<=c+1;j++){
            if( m[i][j]==1){
                m[i][j]=t;
                region(i,j);
                
            }
        }
    }
    
    return;
}
    
int main() { 
    int r,c;
    cin>>r>>c;
    
    for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
        {  cin>>m[i][j];
        
           if(m[i][j]==1 ||m[i][j]==2)
               m[i][j]=1;
         else
             m[i][j]=0;
         
        }
    
    
        
        for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
        if(m[i][j]==1){
        region(i,j);
           t++;
         }         
        }            
    }    
    int ar[t+1]={0};
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++)
        ar[m[i][j]]+=1;
    }
    int max=0;
    for(int i=1;i<=t;i++)
        max=fmax(max,ar[i]);
    
    cout<<max;
        
    return 0;
}





https://www.hackerrank.com/challenges/connected-cell-in-a-grid/problem
Last edited on
anyone wants the first four problems full 100% AC answer. You need only give me any partial or fully solved answer form the last four problem (after the vision problem) . interested students PM me.
Last edited on
can anyone tell that
what are changes have to made in the solution of @iitkgpian to get all AC

uptil now it is giving -
1 0 WA (0.000000)
1 1 AC (0.000000)
1 2 WA (0.000000)
1 3 WA (0.000000)
1 4 AC (0.000000)
Subtask Score: 0.00% Result - WA
2 5 WA
(0.140000)
2 6 AC
(0.140000)
2 7 WA
(0.220000)
2 8 WA
(0.220000)
2 9 AC
(0.110000)
Subtask Score: 0.00% Result - WA
3 10 WA
(0.550000)
3 11 AC
(0.620000)
3 12 WA
(0.520000)
3 13 WA
(0.520000)
3 14 AC
(0.500000)
Subtask Score: 0.00% Result - WA
Total Score = 0.00%
Last edited on
anyone convert this code in such a way that it read two intiger in single line
and the value reading for matrixes if(a[i][j]==1 ||a[i][j]==2) then a[i][j]=1; else a[i][j]=0;
it gives me write answer if take input this way
4
5
1 1 2 3 1
3 1 2 5 2
5 2 1 5 6
1 3 1 2 1

but i want to take input this way
4 5
1 1 2 3 1
3 1 2 5 2
5 2 1 5 6
1 3 1 2 1

and then i want to convert 1 to 1 and 2to 1 and rest to Zero(0).

this way
4 5
1 1 1 0 1
0 1 1 0 1
0 1 1 0 0
1 0 1 1 1


anyone know python can convert this. then it gives correct answer .



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the connectedCell function below.
#def connectedCell(matrix):
def connectedCell(matrix):
    # Complete this function
    result_list = []
    n,m = len(matrix),len(matrix[0])
    for i in range(0,n):
        for j in range(0,m):
            if matrix[i][j] == 1:
                result_list.append(dfs(matrix,i,j))
    return max(result_list)
                
def dfs(matrix,i,j):
    n,m = len(matrix),len(matrix[0])
    if i < 0 or j < 0 or i >= n or j >= m:
        return 0
    if matrix[i][j] == 0:
        return 0
    if matrix[i][j] == 1:
        matrix[i][j] = 0
        return 1+dfs(matrix,i-1,j)+dfs(matrix,i+1,j)+dfs(matrix,i,j-1)+dfs(matrix,i,j+1) 

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    
   
    n = int(input())

    m = int(input())

  # n,m = map(int,sys.stdin.readline().split())

    matrix = []

    for _ in range(n):
        matrix.append(list(map(int, input().rstrip().split())))

    result = connectedCell(matrix)

    fptr.write(str(result) + '\n')

    fptr.close()

Last edited on
@keve
please check ur pm
@yobro pm me too
@wasp done
please help
Pages: 1... 8910111213