Page 4 of 4

Re: 776 - Monkeys in a Regular Forest

Posted: Thu Oct 28, 2010 7:21 am
by zobayer
For those who are in doubt about the input range, no line in input file contains more than 202 characters (including the line-break / new-line character).

Re: 776 - Monkeys in a Regular Forest

Posted: Wed Jul 27, 2011 9:37 am
by MAMU
It seems to me that I didn't get the problem.
Output file has to show lines of integers separated by as many blank spaces as required to align columns to the right.
What does this line mean?
However, how come this input outputs that??

Code: Select all

a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b
a b c d e f g h
h g f e d c a b

Code: Select all

  1   2   3 4 5   6   7   8
  9  10  11 5 4  12  13  14
15  16  17 4 5  18  19  20
21  22  23 5 4  24  25  26
27  28  29 4 5  30  31  32
33  34  35 5 4  36  37  38
39  40  41 4 5  42  43  44
45  46  47 5 4  48  49  50
51  52  53 4 5  54  55  56
57  58  59 5 4  60  61  62
63  64  65 4 5  66  67  68
69  70  71 5 4  72  73  74
75  76  77 4 5  78  79  80
81  82  83 5 4  84  85  86
87  88  89 4 5  90  91  92
93  94  95 5 4  96  97  98
99 100 101 4 5 102 103 104
105 106 107 5 4 108 109 110
111 112 113 4 5 114 115 116
117 118 119 5 4 120 121 122
123 124 125 4 5 126 127 128
129 130 131 5 4 132 133 134
135 136 137 4 5 138 139 140
141 142 143 5 4 144 145 146
147 148 149 4 5 150 151 152
153 154 155 5 4 156 157 158
159 160 161 4 5 162 163 164
165 166 167 5 4 168 169 170
171 172 173 4 5 174 175 176
177 178 179 5 4 180 181 182
183 184 185 4 5 186 187 188
189 190 191 5 4 192 193 194
195 196 197 4 5 198 199 200
201 202 203 5 4 204 205 206
207 208 209 4 5 210 211 212
213 214 215 5 4 216 217 218
219 220 221 4 5 222 223 224
225 226 227 5 4 228 229 230
231 232 233 4 5 234 235 236
237 238 239 5 4 240 241 242
243 244 245 4 5 246 247 248
249 250 251 5 4 252 253 254
255 256 257 4 5 258 259 260
261 262 263 5 4 264 265 266
%
Someone please help...

776 - Monkeys in a Regular Forest

Posted: Tue Feb 04, 2014 8:30 pm
by lukai

Code: Select all

/** verdict:
 *  author: zaman
 *  used algorithm:
 *  remarks:
 *  date: , time of acceptance:
 *  rank:  time:
 *
 */

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;

typedef vector<char>vc;
vector<vc>input;
int Row,Column;
typedef vector<int>vi;
vector<vi>result,space;
vi tempint;
int dr[]={1,1,0,-1,-1,-1,0,1};
int dc[]={0,1,1,1,0,-1,-1,-1};
int counter=0;

int floodfill(int r,int c,char ch1,int replace0)
{
    if(r<0||r>=Row||c<0||c>=Column)
    {
        return 0;
    }
    if(input[r][c]!=ch1)
    {
        return 0;
    }
    input[r][c]='%';
    result[r][c]=replace0;
    for(int d=0;d<8;d++)
    {
        floodfill(r+dr[d],c+dc[d],ch1,replace0);
    }
    return 0;
}


void initresult()
{
    for(int i=0;i<Row;i++)
    {
        for(int j=0;j<Column;j++)
        {
            tempint.push_back(0);

        }
        result.push_back(tempint);
        space.push_back(tempint);
        tempint.clear();
    }

}

void calculate()
{
    for(int i=0;i<Row;i++)
    {
        for(int j=0;j<Column;j++)
        {
            if(input[i][j]!='%')
            {
                counter++;
                char ch=input[i][j];
                floodfill(i,j,ch,counter);
            }
        }
    }

}
void printResult()
{

    for(int i=0;i<Row;i++)
    {
        for(int j=0;j<Column;j++)
        {
            if(j==0)
            {
                for(int k=0;k<space[i][j];k++)
                {
                    cout<<" ";
                }
                cout<<result[i][j];
            }
            else
            {
                cout<<" ";
                for(int k=0;k<space[i][j];k++)
                {
                    cout<<" ";
                }
                cout<<result[i][j];
            }

        }
        cout<<endl;
    }
    cout<<'%'<<endl;
}
void spaceCount()
{

    vi temp,lol;
    lol.assign(Column,0);
    int a,counter2,b;
    for(int i=0;i<Column;i++)
    {
        for(int j=0;j<Row;j++)
        {
            temp.push_back(result[j][i]);
        }
        a=*max_element(temp.begin(),temp.end());
        lol[i]=a;
        temp.clear();
    }
    for(int i=0;i<Column;i++)
    {
        counter2=0;
        a=lol[i];
        while(a)
        {
            a=a/10;
            if(a>0)
            {
                counter2++;
            }
        }
        lol[i]=counter2;
    }

    for(int i=0;i<Row;i++)
    {

        for(int j=0;j<Column;j++)
        {
            counter2=0;
            a=result[i][j];
            while(a)
            {
                a=a/10;
                if(a>0)
                {
                    counter2++;
                }
            }
            b=lol[j]-counter2;
            space[i][j]=b;
        }
    }
    lol.clear();
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	char in1,in2;
	vc tempVector;
    Row=Column=0;
	while(scanf("%c%c",&in1,&in2)!=EOF)
    {
        if(in1=='%' && in2=='\n')
        {
            initresult();
            calculate();
            spaceCount();
            printResult();
            input.clear();
            Row=Column=0;
            result.clear();
            counter=0;
            space.clear();
            in1='\0';
            in2='\0';
        }
        else if((in1>='A'&&in1<='z')&&in2=='\n')
        {
            tempVector.push_back(in1);
            Column=tempVector.size();
            input.push_back(tempVector);
            Row++;
            tempVector.clear();
        }
        else
        {
            tempVector.push_back(in1);
        }

    }
    //tempVector.push_back(in1);
    Column=tempVector.size();
    input.push_back(tempVector);
    Row++;
    tempVector.clear();
    initresult();
    calculate();
    spaceCount();
    printResult();
    input.clear();
    Row=Column=0;
    result.clear();
    counter=0;
    space.clear();

	return 0;
}
Someone please help me, I can't figure out why WA. I am trying this for about two days.

Re: 776 - Monkeys in a Regular Forest

Posted: Tue Feb 04, 2014 9:40 pm
by brianfry713
Doesn't match the sample I/O.

Re: 776 - Monkeys in a Regular Forest

Posted: Tue Feb 04, 2014 10:04 pm
by lukai

Code: Select all

/** verdict:
 *  author: zaman
 *  used algorithm:
 *  remarks:
 *  date: , time of acceptance:
 *  rank:  time:
 *
 */

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;

typedef vector<char>vc;
vector<vc>input;
int Row,Column;
typedef vector<int>vi;
vector<vi>result,space;
vi tempint;
int dr[]={1,1,0,-1,-1,-1,0,1};
int dc[]={0,1,1,1,0,-1,-1,-1};
int counter=0;

int floodfill(int r,int c,char ch1,int replace0)
{
    if(r<0||r>=Row||c<0||c>=Column)
    {
        return 0;
    }
    if(input[r][c]!=ch1)
    {
        return 0;
    }
    input[r][c]='%';
    result[r][c]=replace0;
    for(int d=0;d<8;d++)
    {
        floodfill(r+dr[d],c+dc[d],ch1,replace0);
    }
    return 0;
}


void initresult()
{
    for(int i=0;i<Row;i++)
    {
        for(int j=0;j<Column;j++)
        {
            tempint.push_back(0);

        }
        result.push_back(tempint);
        space.push_back(tempint);
        tempint.clear();
    }

}

void calculate()
{
    for(int i=0;i<Row;i++)
    {
        for(int j=0;j<Column;j++)
        {
            if(input[i][j]!='%')
            {
                counter++;
                char ch=input[i][j];
                floodfill(i,j,ch,counter);
            }
        }
    }

}
void printResult()
{

    for(int i=0;i<Row;i++)
    {
        for(int j=0;j<Column;j++)
        {
            if(j==0)
            {
                for(int k=0;k<space[i][j];k++)
                {
                    cout<<" ";
                }
                cout<<result[i][j];
            }
            else
            {
                cout<<" ";
                for(int k=0;k<space[i][j];k++)
                {
                    cout<<" ";
                }
                cout<<result[i][j];
            }

        }
        cout<<endl;
    }
    cout<<'%'<<endl;
}
void spaceCount()
{

    vi temp,lol;
    lol.assign(Column,0);
    int a,counter2,b;
    for(int i=0;i<Column;i++)
    {
        for(int j=0;j<Row;j++)
        {
            temp.push_back(result[j][i]);
        }
        a=*max_element(temp.begin(),temp.end());
        lol[i]=a;
        temp.clear();
    }
    for(int i=0;i<Column;i++)
    {
        counter2=0;
        a=lol[i];
        while(a)
        {
            a=a/10;
            if(a>0)
            {
                counter2++;
            }
        }
        lol[i]=counter2;
    }

    for(int i=0;i<Row;i++)
    {

        for(int j=0;j<Column;j++)
        {
            counter2=0;
            a=result[i][j];
            while(a)
            {
                a=a/10;
                if(a>0)
                {
                    counter2++;
                }
            }
            b=lol[j]-counter2;
            space[i][j]=b;
        }
    }
    lol.clear();
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	char in1,in2;
	vc tempVector;
    Row=Column=0;
	while(scanf("%c%c",&in1,&in2)!=EOF)
    {
        if(in1=='%' && in2=='\n')
        {
            initresult();
            calculate();
            spaceCount();
            printResult();
            input.clear();
            Row=Column=0;
            result.clear();
            counter=0;
            space.clear();
            in1='\0';
            in2='\0';
        }
        else if((in1>='A'&&in1<='z')&&in2=='\n')
        {
            tempVector.push_back(in1);
            Column=tempVector.size();
            input.push_back(tempVector);
            Row++;
            tempVector.clear();
            in1='\0';
            in2='\0';
        }
        else if((in1>='A'&&in1<='z')&&in2=='\0')
        {
            tempVector.push_back(in1);
            Column=tempVector.size();
            input.push_back(tempVector);
            Row++;
            tempVector.clear();
            initresult();
            calculate();
            spaceCount();
            printResult();
            input.clear();
            Row=Column=0;
            result.clear();
            counter=0;
            space.clear();
            in1='\0';
            in2='\0';

        }
        else
        {
            tempVector.push_back(in1);
            in1='\0';
            in2='\0';
        }

    }
	return 0;
}
here is my code :( still WA. can you give me some critical I/O

Re: 776 - Monkeys in a Regular Forest

Posted: Thu Feb 06, 2014 7:57 am
by lukai
Plz somebody help

Re: 776 - Monkeys in a Regular Forest

Posted: Thu Feb 06, 2014 10:44 pm
by brianfry713
There will be a newline char at the end of the last line in the judge's input.