Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by operator on 07.03.2017.
- */
- public class Punkty {
- double x;
- double y;
- public Punkty(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public double getX() {
- return x;
- }
- public void setX(double x) {
- this.x = x;
- }
- public double getY() {
- return y;
- }
- public void setY(double y) {
- this.y = y;
- }
- }
- ///////////////////////////////////////////////////////////////
- /**
- * Created by operator on 07.03.2017.
- */
- public class Okrag implements Comparable<Okrag>{
- double x;
- double y;
- double z;
- public Okrag(double x, double y, double z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public double getX() {
- return x;
- }
- public void setX(double x) {
- this.x = x;
- }
- public double getY() {
- return y;
- }
- public void setY(double y) {
- this.y = y;
- }
- public double getZ() {
- return z;
- }
- public void setZ(double z) {
- this.z = z;
- }
- @Override
- public int compareTo(Okrag o) {
- if (this.getX()<o.getX()) return -1;
- else if (this.getX()>o.getX()) return 1;
- else if (this.getY()<o.getY()) return -1;
- else if (this.getY()>o.getY()) return 1;
- else return 0;
- }
- @Override
- public String toString() {
- return x + " " + y + " " + z;
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- /**
- * Created by operator on 07.03.2017.
- */
- public class Matura2017 {
- public static double distanceSqrt(double ax,double ay,double bx,double by){
- return Math.sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
- }
- public static double distanceNoSqrt(double ax,double ay,double bx,double by){
- return (ax-bx)*(ax-bx)+(ay-by)*(ay-by);
- }
- public static double obliczPole(double ax,double ay,double bx,double by,double cx,double cy){
- double s_ab=distanceSqrt(ax,ay,bx,by);
- double s_ac=distanceSqrt(ax,ay,cx,cy);
- double s_bc=distanceSqrt(bx,by,cx,cy);
- double p=(s_ab+s_bc+s_ac)/2;
- //System.out.println("P ="+p);
- //System.out.println("Pole ="+pole);
- //System.out.println("M ="+Math.sqrt(p*(p-s_ab)*(p-s_ac)*(p-s_bc)));
- return Math.sqrt(p*(p-s_ab)*(p-s_ac)*(p-s_bc));
- }
- public static void main(String[] args) throws FileNotFoundException {
- File file1=new File("punkty.txt");
- File file2=new File("okregi.txt");
- PrintWriter wyniki1=new PrintWriter("wyniki1.txt");
- PrintWriter wyniki2=new PrintWriter("wyniki2.txt");
- PrintWriter wyniki3=new PrintWriter("wyniki3.txt");
- Scanner scanner=new Scanner(file1);
- int liczba=0;
- int [] cwiartki={0,0,0,0,0};
- String wiersz;
- String [] punkty;
- ArrayList<Punkty> lista=new ArrayList<Punkty>();
- while (scanner.hasNextLine()){
- wiersz=scanner.nextLine();
- punkty=wiersz.split(" ");
- lista.add(new Punkty(Double.parseDouble(punkty[0]),Double.parseDouble(punkty[1])));
- if (Double.parseDouble(punkty[0])>0 && Double.parseDouble(punkty[1])>0)
- cwiartki[1]++;
- else if (Double.parseDouble(punkty[0])<0 && Double.parseDouble(punkty[1])>0)
- cwiartki[2]++;
- else if (Double.parseDouble(punkty[0])<0 && Double.parseDouble(punkty[1])<0)
- cwiartki[3]++;
- else cwiartki[4]++;
- }
- wyniki1.println(cwiartki[1]+" "+cwiartki[2]+" "+cwiartki[3]+" "+cwiartki[4]);
- wyniki1.close();
- //######
- ArrayList<Okrag> tablica=new ArrayList<Okrag>();
- scanner=new Scanner(file2);
- String [] okregi;
- while (scanner.hasNextLine()){
- wiersz=scanner.nextLine();
- okregi=wiersz.split(" ");
- tablica.add(new Okrag(Double.parseDouble(okregi[0]),Double.parseDouble(okregi[1]),Double.parseDouble(okregi[2])));
- }
- //System.out.print(tablica);
- Collections.sort(tablica);
- int licznik=0;
- for (Okrag i:tablica
- ) {
- if ((distanceSqrt(i.getX(), i.getY(), i.getX(),0) == i.getZ())) {
- wyniki2.println(i);
- licznik++;
- }
- }
- wyniki2.println(licznik);
- wyniki2.close();
- //##################
- double pole=0;
- double p;
- // System.out.println(distanceSqrt(51,284,0,5184));
- for (int i=0;i<lista.size()-1;i=i+1){
- pole=pole+obliczPole(lista.get(i).getX(),lista.get(i).getY(),lista.get(i+1).getX(),lista.get(i+1).getY(),0,0);
- }
- pole=pole+obliczPole(lista.get(lista.size()-1).getX(),lista.get(lista.size()-1).getY(),lista.get(0).getX(),lista.get(0).getY(),0,0);
- wyniki3.println((int)pole);
- wyniki3.close();
- System.out.println("POLE "+(int)pole);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment