Day 8
This commit is contained in:
parent
8fe274116c
commit
e12db36a20
|
@ -0,0 +1,93 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string line;
|
||||
getline(cin, line);
|
||||
|
||||
int length = line.size();
|
||||
|
||||
int* forest = new int[length*length];
|
||||
int in_y = 0;
|
||||
do
|
||||
{
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
forest[i+in_y*length] = line[i]-'0';
|
||||
}
|
||||
++in_y;
|
||||
} while(getline(cin, line));
|
||||
|
||||
bool* visible = new bool[length*length];
|
||||
for(int i = 0; i < length*length; i++)
|
||||
{
|
||||
visible[i] = false;
|
||||
}
|
||||
|
||||
for(int x = 0; x < length; x++)
|
||||
{
|
||||
//top down
|
||||
int vis_height = -1;
|
||||
for(int y = 0; y < length; y++)
|
||||
{
|
||||
if (forest[x+y*length] > vis_height)
|
||||
{
|
||||
vis_height = forest[x+y*length];
|
||||
visible[x+y*length] = true;
|
||||
}
|
||||
}
|
||||
|
||||
//bottom up
|
||||
vis_height = -1;
|
||||
for(int y = length-1; y >= 0; y--)
|
||||
{
|
||||
if (forest[x+y*length] > vis_height)
|
||||
{
|
||||
vis_height = forest[x+y*length];
|
||||
visible[x+y*length] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int y = 0; y < length; y++)
|
||||
{
|
||||
//Left right
|
||||
int vis_height = -1;
|
||||
for(int x = 0; x < length; x++)
|
||||
{
|
||||
if (forest[x+y*length] > vis_height)
|
||||
{
|
||||
vis_height = forest[x+y*length];
|
||||
visible[x+y*length] = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Right left
|
||||
vis_height = -1;
|
||||
for(int x = length-1; x >= 0; x--)
|
||||
{
|
||||
if (forest[x+y*length] > vis_height)
|
||||
{
|
||||
vis_height = forest[x+y*length];
|
||||
visible[x+y*length] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int total_vis = 0;
|
||||
for(int i = 0; i < length*length; i++)
|
||||
{
|
||||
if(visible[i])
|
||||
{
|
||||
++total_vis;
|
||||
}
|
||||
}
|
||||
|
||||
cout << total_vis << endl;
|
||||
|
||||
delete[] visible;
|
||||
delete[] forest;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string line;
|
||||
getline(cin, line);
|
||||
|
||||
int length = line.size();
|
||||
|
||||
int* forest = new int[length*length];
|
||||
int in_y = 0;
|
||||
do
|
||||
{
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
forest[i+in_y*length] = line[i]-'0';
|
||||
}
|
||||
++in_y;
|
||||
} while(getline(cin, line));
|
||||
|
||||
int best_vis = 0;
|
||||
for(int y = 0; y < length; y++)
|
||||
{
|
||||
for(int x = 0; x < length; x++)
|
||||
{
|
||||
int north_vis = 0;
|
||||
int south_vis = 0;
|
||||
int west_vis = 0;
|
||||
int east_vis = 0;
|
||||
int cur_vis = forest[x+y*length];;
|
||||
|
||||
for(int j = y-1; j >= 0; j--)
|
||||
{
|
||||
north_vis++;
|
||||
if (forest[x+j*length] >= cur_vis)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = y+1; j < length; j++)
|
||||
{
|
||||
south_vis++;
|
||||
if (forest[x+j*length] >= cur_vis)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = x-1; i >= 0; i--)
|
||||
{
|
||||
west_vis++;
|
||||
if (forest[i+y*length] >= cur_vis)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = x+1; i<length; i++)
|
||||
{
|
||||
east_vis++;
|
||||
if(forest[i+y*length] >= cur_vis)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int total_vis = north_vis*south_vis*east_vis*west_vis;
|
||||
|
||||
if (total_vis > best_vis)
|
||||
{
|
||||
best_vis = total_vis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << best_vis << endl;
|
||||
|
||||
delete[] forest;
|
||||
}
|
Loading…
Reference in New Issue