• Java面向对象4(P~U)


    P    3-1 Point类的构造函数 (SDUT 2670)

    import java.util.Arrays;
    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int x,y;
    		x = sc.nextInt();
    		y = sc.nextInt();
    		System.out.println("(0,0)");
    		System.out.println("(" + x + "," + y + ")");
    	}
    }
    

    最佳拟合直线(SDUT 2728)

    import java.util.Scanner;
     
    public class Main {
    	static int n;
    	static double sum(double x[])  
    	{  
    	    double s=0;  
    	    for(int i=0;i<n;i++)  
    	    s+=x[i];  
    	    return s;   
    	}
    	public static void main(String[] args) {
    		Scanner  in = new Scanner(System.in);
    		double x[] = new double [20];
    		double y[] = new double [20];
    		double c[] = new double [20];
    		double d[] = new double [20];
    		double a1,b1,o;
    		n = in.nextInt();
    		for(int i = 0; i < n; i++){
    			x[i] = in.nextDouble();
    			y[i] = in.nextDouble();
    			c[i] = x[i] * y[i];
    			d[i] = x[i] * x[i];
    		}
    		a1 = n * sum(c) - sum(x) * sum(y);
    		b1 = sum(y) * sum(d) -sum(x) * sum(c);
    		o = n * sum(d) - Math.pow(sum(x), 2);
    		System.out.printf("%.3f
    ",a1/o);
    		System.out.printf("%.3f
    ",b1/o);
    	}
    }
    	 

    区域内点的个数(SDUT 2749)

    //转载
    import java.util.Scanner;
     
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		while (sc.hasNext()) {
    			int count = sc.nextInt();
    			Point[] points = new Point[count];
    			int px1 = sc.nextInt();
    			int py1 = sc.nextInt();
    			int px2 = sc.nextInt();
    			int py2 = sc.nextInt();
    			Point p1 = new Point(px1, py1);
    			Point p2 = new Point(px2, py2);
    			int resultCount = 0;
    			for (int i = 0; i < count; i++) {
    				points[i] = new Point(sc.nextInt(), sc.nextInt());
    				if (points[i].inRect(p1, p2)) {
    					resultCount++;
    				}
    			}
    			System.out.println(resultCount);
    		}
     
    		sc.close();
    	}
    }
     
    class Point {
    	int x;
    	int y;
     
    	public Point(int x, int y) {
    		this.x = x;
    		this.y = y;
    	}
     
    	public boolean inRect(Point p1, Point p2) {
    		boolean flag = false;
    		if (x > p1.x && x < p2.x && y > p1.y && y < p2.y) {
    			flag = true;
    		}
    		return flag;
    	}
    }

    谁是最强的女汉子(SDUT 3081)

    import java.text.DecimalFormat;
    import java.util.Scanner;
     
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		long []a = new long [11000]; 
    		long []b = new long [11000];
    		int n = sc.nextInt();
    	    a[0] = sc.nextLong();
    	    b[0] = sc.nextLong();
    	    long min = a[0];
    	    int c = 0;
    	    long sum = 0;
    		for(int i = 1 ;i < n; i++) {
    			a[i] = sc.nextLong();
    			b[i] = sc.nextLong();
    			if(min > a[i]) {
    				min = a[i];
    			}
    		}
    		for(int i = 0 ;i < n ; i ++) {
    			if(min == a[i]) {
    				c++;
    				sum += b[i];
    			}
    		}
    		System.out.println(c+" "+sum);
    }
    }

    飞花的糖果(SDUT 3268)

    import java.util.Scanner;  
    class Candy{
    	int m, n;
    	public Candy(int n, int m) {
    		super();
    		this.m = m;
    		this.n = n;
    	}
    	
    	public int count() {
    		int s1 =1;
    		int s2 =1;
    		for(int i=n; i>n-m; i--) {
    			s1 *= i;
    		}
    		for(int i=2; i<=m; i++) {
    			s2 *= i;
    		}
    		return s1/s2;
    	}
    	
    }
    public class Main  {  
       public static void main(String[] args) {  
          Scanner reader = new Scanner(System.in);  
          while(reader.hasNext()) {
        	  int n = reader.nextInt();
        	  int m = reader.nextInt();
        	  Candy candy = new Candy(n, m);
        	  System.out.println(candy.count());
          }
       }  
    }   

     计算长方体、四棱锥的表面积和体积(SDUT 3337)

    import java.text.DecimalFormat;
    import java.util.Scanner;
    
    public class Main {
    	
    	public static void main(String[] args) {
    		Scanner in = new Scanner (System.in);
    		while( in.hasNext() ){
    			double l = in.nextInt();
    			double h = in.nextInt();
    			double z = in.nextInt();
    			Cubic cub = new Cubic(l, h, z);
    			Pyramid py = new Pyramid(l, h, z);
    			DecimalFormat m = new DecimalFormat("0.00");
    			System.out.println(m.format(cub.area()) + " " + m.format(cub.volumn()) +" "
    					+ m.format(py.area()) + " " + m.format(py.volumn()) );
    		}
    		in.close();
    	}
    }
     
    class Rect {
    	double leng, high, zi;
    	
    	public Rect(double l, double h, double z ){
    		if( l>0 && h>0 && z>0 ){
    			this.leng = l;
    			this.high = h;
    			this.zi = z;
    		}
    	}
    	
    	public double length(){
    		return 2*(leng+high);
    	}
    	
    	public double area(){
    		return leng*high;
    	}
    }
     
    class Cubic extends Rect{
    	
    	public Cubic (double l, double h, double z ){
    		super(l, h, z);	
    	}
    	
    	public double area(){
    		return 2*super.area()+length()*zi;
    	}
    	
    	public double volumn(){
    		return super.area()*zi;
    	}
    }
     
    class Pyramid extends Rect{
    	public Pyramid( double l, double h, double z ){
    		super(l, h, z);
    	}
    	
    	public double area(){
    		return super.area() + leng*Math.sqrt(zi*zi+high*high/4) + high*Math.sqrt(zi*zi+leng*leng/4);
    	}
    	
    	public double volumn(){
    		return super.area()*zi/3;
    	}
    }
  • 相关阅读:
    [整理]弦图学习笔记
    [整理]NOI Online 2021第一场题解
    [整理]Pólya 定理入门到入土
    [游记]2021省选抱灵记
    [整理]一些好玩的/板子的动态规划题目
    [整理]网络流随记——终(有关网络流的一些杂项)
    [整理][持续更新]多项式知识点大全(超简洁!)
    [洛谷P4338][题解][ZJOI2018]历史
    [游记]WC2021游记
    Codeforces Round #703 (Div. 2) (A~E)
  • 原文地址:https://www.cnblogs.com/lcchy/p/10139476.html
Copyright © 2020-2023  润新知