原題下載
答案:
import java.io.*;
import java.util.*;
public class square {
public static void main(String[] args) throws IOException {
// initialize file I/O
BufferedReader br = new BufferedReader(new FileReader("square.in"));
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("square.out")));
// track the bottom, top, left, and rightmost points that need to be covered
int smallestX = 10;
int largestX = 0;
int smallestY = 10;
int largestY = 0;
// read in two lines, store corners of the pastures
for(int i = 0; i < 2; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int xLow = Integer.parseInt(st.nextToken());
int yLow = Integer.parseInt(st.nextToken());
int xHigh = Integer.parseInt(st.nextToken());
int yHigh = Integer.parseInt(st.nextToken());
if(xLow < smallestX) {
smallestX = xLow;
}
if(xHigh > largestX) {
largestX = xHigh;
}
if(yLow < smallestY) {
smallestY = yLow;
}
if(yHigh > largestY) {
largestY = yHigh;
}
}
// compute the desired side length of the square
int desiredSideLength = largestX - smallestX;
if(largestY - smallestY > largestX - smallestX) {
desiredSideLength = largestY - smallestY;
}
// print the answer
pw.println(desiredSideLength * desiredSideLength);
pw.close();
}
}
以上就是關于【USACO 2016 December Contest, Bronze Problem 1. Square Pasture】的解答,如需了解學校/賽事/課程動態,可至翰林教育官網獲取更多信息。
往期文章閱讀推薦:
2026 NOAI國際AI奧賽中國站即將開考!賽事地址&日程已出!
2027 USAAIO美國AI奧賽啟動報名!MIT/谷歌/Jane Street集體站臺!

? 2026. All Rights Reserved. 滬ICP備2023009024號-1