-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday14-part1.cpp
75 lines (73 loc) · 1.46 KB
/
day14-part1.cpp
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
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int vis[1500][1500];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
for (string s; getline(cin, s);) {
vector <pair<int,int> > v;
int dec;
char ch; // ,
int frac;
string str;
stringstream sstream = stringstream(s);
while(sstream >> dec >> ch >> frac){
sstream >> str;// ->
v.pb({dec,frac});
}
v.pb({dec,frac});
for(int i=1;i<v.size();i++){
auto x = v[i-1];
auto y = v[i];
if(x.first == y.first){
int minx = min(x.second,y.second);
int maxx = max(x.second,y.second);
for(int j=minx;j<=maxx;j++){
vis[j][x.first] = 1;
}
}
if(x.second == y.second){
int minx = min(x.first,y.first);
int maxx = max(x.first,y.first);
for(int j=minx;j<=maxx;j++){
vis[x.second][j] = 1;
}
}
}
}
int ans=0;
while(1){
int y = 500;
int x = 0;
bool flag = true;
while(1){
if(vis[x+1][y+1] == 1 and vis[x+1][y-1] == 1 and vis[x+1][y] == 1){
vis[x][y] = 1;
break;
}
else if(vis[x+1][y] == 0){ // down is empty
x++;
}
else if(vis[x+1][y]==1 and vis[x+1][y-1]==0){ // left down
x++;
y--;
}
else if(vis[x+1][y]==1 and vis[x+1][y-1]==1 and vis[x+1][y+1]==0){ // right down
x++;
y++;
}
if(x==999){
flag = false;
break;
}
}
if(flag==false){
break;
}
ans++;
}
cout << ans << endl;
}