蓝桥杯31天冲刺之二十二 [java]

ASC

题目:已知大写字母 A 的 ASCII 码为 65,请问大写字母 L 的 ASCII 码是多少?

题目链接:https://www.lanqiao.cn/problems/1446/learning/

这直接算就好了,没啥说的

可以从A去算L的ASCII,也可以直接输出L的ASCII

package daily;

/**
 * https://www.lanqiao.cn/problems/1446/learning/
 * 
 * @author Jia
 *
 */
public class day3_29_1 {
    
    
	public static void main(String[] args) {
    
    
		System.out.println((int) 'L');
	}
}

排列数

image-20220329131528072

题目链接:http://lx.lanqiao.cn/problem.page?gpid=T2716

这个题可以直接暴力做了,然后拿一部分分,感觉如果要拿满分的话需要用dp去解,但是找不到递推方程,就不做了,暴力的话直接回溯找到所有的排列方式然后判断是不是符合条件就可以了
找到了一个用dp做的大佬,想学习的可以看看,但是我感觉有点难,解析链接

平面切分

image-20220329132239128

题目链接:http://lx.lanqiao.cn/problem.page?gpid=T798

题目分析:

  • 一个平面被一条线切割会比原来的平面多出一个平面。
  • 如果这个时候再次多出一条跟上面的线平行的线再次切割,那么会又多出一个平面。
  • 如果一条线和别的线产生交点,那么这条线切割平面会多出:这条直线和别的直线相交出的点的个数+1。

然后知道了上面这个东西就可以去模拟做题了,这个题感觉主要是上面这个东西不容易找到规律,找到之后还能好做一点

另外需要注意的就是一个直线和其他直线的交点可能会有重复的,例如一个直线和另外两条直线交到一点,那么这个只能算是一个点,所以我在代码中用到了hashset去掉重复的点

另外推荐大家看一道类似的题(2020年A组题):http://oj.ecustacm.cn/problem.php?id=1512

package daily;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * http://lx.lanqiao.cn/problem.page?gpid=T798
 * 
 * @author Jia
 *
 */
public class day3_29_3 {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<Line> lineSet = new HashSet<>();
		for (int i = 0; i < N; i++) {
    
    
			int A = sc.nextInt();
			int B = sc.nextInt();
			lineSet.add(new Line(A, B));
		}
		sc.close();

		long ans = 2;// 一个直线可以将平面分为两个部分
		Line[] lines = lineSet.toArray(new Line[0]);
		for (int i = 1; i < lines.length; i++) {
    
    
			Set<Point> pointSet = new HashSet<>();
			Line newLine = lines[i];
			for (int j = 0; j < i; j++) {
    
    
				Line oldLine = lines[j];
				if (oldLine.A == newLine.A) {
    
    
					// 两线平行,无交点
					continue;
				} else {
    
    
					double x = (double) (newLine.B - oldLine.B) / (oldLine.A - newLine.A);
					double y = newLine.A * x + newLine.B;
					pointSet.add(new Point(x, y));// 去掉重复的交点
				}
			}
			ans += pointSet.size() + 1;
		}
		System.out.println(ans);
	}
}

class Line {
    
    
	int A;
	int B;

	public Line(int a, int b) {
    
    
		super();
		A = a;
		B = b;
	}

	@Override
	public int hashCode() {
    
    
		return A * 101 + B * 103;
	}

	@Override
	public boolean equals(Object obj) {
    
    
		Line newLine = (Line) obj;
		return A == newLine.A && B == newLine.B;
	}
}

class Point {
    
    
	double x;
	double y;

	public Point(double x, double y) {
    
    
		super();
		this.x = x;
		this.y = y;
	}

	@Override
	public int hashCode() {
    
    
		return (int) x * 101 + (int) y * 103;
	}

	@Override
	public boolean equals(Object obj) {
    
    
		Point newPoint = (Point) obj;
		return x == newPoint.x && y == newPoint.y;
	}
}

猜你喜欢

转载自blog.csdn.net/qq_46311811/article/details/123833179