Day8
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user