Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <iomanip>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cctype>
- #include <cstring>
- #include <vector>
- #include <list>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <iterator>
- #include <bitset>
- #include <ctime>
- using namespace std;
- #define F(i, n) for(int i = 0; i < n; ++i)
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
- #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a,value) memset(a, value, sizeof(a))
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL) INF;
- const int MAX = 3*5555;
- struct point
- {
- int x, y;
- point(int x = 0, int y = 0) : x(x), y(y) {}
- point operator-(const point& p)const
- {
- return point(x-p.x, y-p.y);
- }
- int operator*(const point& p)const
- {
- return x * p.y - y * p.x;
- }
- int dot(const point& p)const
- {
- return x * p.x + y * p.x;
- }
- point operator-()const
- {
- return point()-*this;
- }
- };
- bool par(const point& A, const point &B)
- {
- return (A * B) == 0 && A.dot(B) >= 0;
- }
- bool in_range(const point& A, const point & B, bool a, bool b, const point& X)
- {
- if (par(A, X))return a;
- if (par(X, B))return b;
- if ((A * B) < 0)
- return (A * X) > 0 || (X * B) > 0;
- return (A * X) > 0 && (X * B) > 0;
- }
- point P[22];
- int main()
- {
- //freopen("in.txt", "r", stdin);
- FOR(i, 0, 4)
- FOR(j, 0, 4)
- {
- int x;
- cin >> x;
- --x;
- P[x] = point(j, i);
- }
- point L, R;
- L = R = P[1] - P[0];
- bool l = 1, r = 1;
- int ans = 1;
- FOR(i, 1, 15)
- {
- if (in_range(L, R, l, r, P[i+1] - P[i]))
- {
- L = R = P[i+1] - P[i];
- l = r = 1;
- }
- else
- {
- ans++;
- point NL = -L;
- point NR = -R;
- l = r = 0;
- if (!in_range(NL, NR, 0, 0, P[i+1] - P[i]))
- {
- if (in_range(R, NL, 1, 1, P[i+1] - P[i]))
- {
- NL = P[i+1] - P[i];
- l = 1;
- }
- else
- {
- NR = P[i+1] - P[i];
- r = 1;
- }
- }
- L = NL;
- R = NR;
- }
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement