Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int maxn = 5010;
- struct seg{
- int x1 , y1 , x2 , y2 ;
- seg() {
- x1 = y1 = x2 = y2 = 0 ;
- }
- seg( int _x1 , int _y1 , int _x2 , int _y2) {
- x1 = _x1 ;
- y1 = _y1 ;
- x2 = _x2 ;
- y2 = _y2 ;
- }
- void input () {
- cin>> x1 >> y1 >> x2 >> y2 ;
- }
- };
- int n;
- seg p [maxn] ;
- set < pair < int , int > > pst ;
- void walkthrough(int x1, int y1 ,int x2 , int y2 , int dx , int dy){
- for( int x = x1, y = y1 ; x <= x2 ; x += dx , y += dy)
- pst . insert ( { x , y } ) ;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> n ;
- for ( int i = 0 ; i < n ; ++ i )
- p [i] . input () ;
- for ( int i = 0 ; i < n ; ++ i ){
- if ( p [i] . x1 == p [i] . x2){
- if( p [i] . y1 < p [i] . y2)
- for ( int y = p [i] . y1 ; y <= p [i] . y2 ; ++ y)
- pst . insert ( { p [i] . x1 , y } ) ;
- else for ( int y = p [i] . y2 ; y <= p [i] . y1 ; ++ y)
- pst . insert ( { p [i] . x1 , y } ) ;
- }
- else if ( p [i] . y1 == p [i] . y2){
- if( p [i] . x1 < p [i] . x2)
- for ( int x = p [i] . x1 ; x <= p [i] . x2 ; ++ x)
- pst . insert ( { x , p [i] . y1 } ) ;
- else for ( int x = p [i] . x2 ; x <= p [i] . x1 ; ++ x)
- pst . insert ( { x , p [i] . y1 } ) ;
- }
- else{
- int difx = abs ( p [i] . x2 - p [i] . x1 ) ;
- int dify = abs ( p [i] . y2 - p [i] . y1 ) ;
- int gcd = __gcd ( difx , dify ) ;
- int dx = difx / gcd ;
- int dy = dify / gcd ;
- /*walkthrough ( min ( p [i] . x1 , p [i] . x2) , min ( p [i] . y1 , p [i] . y2 ) ,
- max ( p [i] . x2 , p [i] . x2) , max ( p [i] . y1 , p [i] . y2 ) ,
- dx , dy ) ;*/
- if ( p [i] . x1 < p [i] . x2){
- if ( p [i] . y1 < p [i] . y2){
- int x = p [i] . x1 ;
- int y = p [i] . y1 ;
- for ( ; x <= p [i] . x2 ; x += dx , y += dy )
- pst . insert ( { x , y } ) ;
- }
- else{
- int x = p [i] . x1 ;
- int y = p [i] . y2 ;
- for ( ; x <= p [i] . x2 ; x += dx , y += dy )
- pst . insert ( { x , y } ) ;
- }
- }
- else{
- if ( p [i] . y1 < p [i] . y2){
- int x = p [i] . x2 ;
- int y = p [i] . y1 ;
- for ( ; x <= p [i] . x1 ; x += dx , y += dy )
- pst . insert ( { x , y } ) ;
- }
- else{
- int x = p [i] . x2 ;
- int y = p [i] . y2 ;
- for ( ; x <= p [i] . x1 ; x += dx , y += dy )
- pst . insert ( { x , y } ) ;
- }
- }
- }
- }
- cout << pst . size () << "\n" ;
- /*auto it = pst . begin () ;
- for ( ; it != pst . end () ; ++ it)
- cout << it -> first << " " << it -> second << "\n" ;*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement