Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Point;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class Main {
- private Scanner scan;
- public void run() throws FileNotFoundException {
- scan = new Scanner(new File("./mowing.in"));
- int n, t;
- n = scan.nextInt();
- t = scan.nextInt();
- Point coords[] = new Point[ n ];
- for( int i = 0; i < n; i++ )
- {
- coords[i] = new Point();
- coords[i].x = scan.nextInt();
- coords[i].y = scan.nextInt();
- }
- int fh = (coords[0].y == coords[1].y) ? 1 : 0;
- int ANS = 0;
- for( int i = n-1; i > 0; i-- )
- {
- for( int j = i-t-1; j > 0; j-- )
- {
- if( i % 2 == fh ) // if horiz
- {
- int bigx = Math.max( coords[i].x, coords[i-1].x );
- int smallx = Math.min( coords[i].x, coords[i-1].x );
- int bigy = Math.max( coords[j].y, coords[j-1].y );
- int smally = Math.min( coords[j].y, coords[j-1].y );
- if( coords[i].y > smally && coords[i].y < bigy &&
- coords[j].x > smallx && coords[j].x < bigx )
- {
- ANS++;
- }
- } else // if vert
- {
- int bigy = Math.max( coords[i].y, coords[i-1].y );
- int smally = Math.min( coords[i].y, coords[i-1].y );
- int bigx = Math.max( coords[j].x, coords[j-1].x );
- int smallx = Math.min( coords[j].x, coords[j-1].x );
- if( coords[j].y > smally && coords[j].y < bigy &&
- coords[i].x > smallx && coords[i].x < bigx )
- {
- ANS++;
- }
- }
- }
- }
- PrintWriter pw = new PrintWriter(new File("./mowing.out"));
- pw.println( ANS );
- pw.close();
- scan.close();
- }
- public static void main(String[] args) {
- Main main = new Main();
- try {
- main.run();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement