Language: C++

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

static const double EPS = 1e-10;
const double INF = 1e12;
typedef complex<double> P,point;
 
std::istream& operator>>(std::istream& is,P& p)
{
	is >> p.real() >> p.imag();
	return is;
}

typedef vector<P> G,polygon;
struct L : public vector<P> {L(const P &a, const P &b) {push_back(a); push_back(b);} L(){push_back(P(0,0)); push_back(P(0,0));}};
namespace std {bool operator < (const P& a, const P& b) {return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);} }
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}

bool intersectLL(const L &l, const L &m) {return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;}

P crosspoint(const L &l, const L &m) {
	double A = cross(l[1] - l[0], m[1] - m[0]);
	double B = cross(l[1] - l[0], l[1] - m[0]);
	if (abs(A) < EPS && abs(B) < EPS) return m[0];
	return m[0] + B / A * (m[1] - m[0]);
}
bool intersectSP(const L &s, const P &p) {return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS;}


struct Node{
	int id;
	double dir;
	double cost;
	Node(int id,double dir,double cost) : id(id),dir(dir),cost(cost){}
};
bool operator <(const Node &a,const Node &b){
	return a.cost > b.cost;
}

double PI = acos(-1);
double fix(double x){
	while( x >= 2 * PI ) x -= 2 * PI;
	while( x < 0) x += 2 * PI;
	return x;
}
int main(){
	int n;
	while(cin >> n && n){
		L l[n];
		for(int i = 0 ; i < n ; i++) cin >> l[i][0] >> l[i][1];
		vector<P> tar;
		for(int i = 0 ; i < n ; i++){
			tar.push_back(l[i][0]);
			tar.push_back(l[i][1]);
			for(int j = 0 ; j < n ; j++){
				if( intersectLL(l[i],l[j]) ) tar.push_back(crosspoint(l[i],l[j]));
			}
		}
		P s,g;
		cin >> s >> g;
		tar.push_back(s);
		tar.push_back(g);
		
		vector< vector<int> > connect(tar.size());
		for(int i = 0 ; i < tar.size() ; i++){
			for(int j = i+1 ; j < tar.size() ; j++){
				for(int k = 0 ; k < n ; k++){
					if( abs(tar[i]-tar[j]) < EPS || intersectSP(l[k],tar[i]) && intersectSP(l[k],tar[j]) ){
						connect[i].push_back(j);
						connect[j].push_back(i);
						break;
					}
				}
			}
		}
		priority_queue<Node> Q;
		Q.push(Node(tar.size()-2,-114514,0));
		
		map< pair<int,double> , int> done;
		
		double res = -1;
		while( Q.size() ){
			Node q = Q.top(); Q.pop();
			if( done[make_pair(q.id,q.dir)]++ ) continue;
			P my = tar[q.id];
			if( tar.size() - 1 == q.id ){
				res = q.cost;
				break;
			}
			for(int i = 0 ; i < connect[q.id].size() ; i++){
				int eid = connect[q.id][i];
				P ene = tar[eid];
				ene -= my;
				double rad = atan2(ene.imag(),ene.real());
				rad = fix(rad);
				double diff = fabs(q.dir-rad);
				diff = min(2*PI-diff,diff);
				
				if( q.dir == -114514 ) diff = 0;
				Q.push(Node(eid,rad,q.cost+diff));
			}
		}
		if( res < 0 ){
			cout << -1 << endl;
		}else{
			printf("%.10lf\n",res*180/PI);
		}
	}
}

Compiler output:
a.cc: In function 'std::istream& operator>>(std::istream&, P&)':
a.cc:27:12: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'double')
   27 |         is >> p.real() >> p.imag();
      |         ~~ ^~ ~~~~~~~~
      |         |           |
      |         |           double
      |         std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/iostream:42,
                 from a.cc:9:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  219 |       operator>>(float& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:219:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'float&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  223 |       operator>>(double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:223:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'double&' to an rvalue of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
/usr/include/c++/14/istream:227:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  227 |       operator>>(long double& __f)
      |       ^~~~~~~~
/usr/include/c++/14/istream:227:7: note:   conversion of argument 1 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'long double&' to a value of type 'double'
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
a.cc:25:15: note: candidate: 'std::istream& operator>>(std::istream&, P&)' (near match)
   25 | std::istream& operator>>(std::istream& is,P& p)
      |               ^~~~~~~~
a.cc:25:15: note:   conversion of argument 2 would be ill-formed:
a.cc:27:21: error: cannot bind non-const lvalue reference of type 'P&' {aka 'std::complex<double>&'} to an rvalue of type 'P' {aka 'std::complex<double>'}
   27 |         is >> p.real() >> p.imag();
      |               ~~~~~~^~
In file included from a.cc:16:
/usr/include/c++/14/complex:1514:26: note:   after user-defined conversion: 'constexpr std::complex<double>::complex(double, double)'
 1514 |       _GLIBCXX_CONSTEXPR complex(double __r = 0.0, double __i = 0.0)
      |                          ^~~~~~~
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  328 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/14/istream:328:25: note:   no known conversion for argument 1 from 'double' to 'void*&'
  328 |       operator>>(void*& __p)
      |                  ~~~~~~~^~~
/usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:122:36: note:   no known conversion for argument 1 from 'double' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'}
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]'
  126 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:126:32: note:   no known conversion for