【第一题完全通过】 【思路】由于给的是平面坐标,判定条件:四条较小的点点距离相等,两条较大的点点距离相等 【定理】四条边相等 -》 菱形    菱形对角线相等 -》正方形 import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         int n = sc.nextInt();                  for (int i = 0; i < n; i++)         {                 int n1_x = sc.nextInt();                 int n2_x = sc.nextInt();                 int n3_x = sc.nextInt();                 int n4_x = sc.nextInt();                                  int n1_y = sc.nextInt();                 int n2_y = sc.nextInt();                 int n3_y = sc.nextInt();                 int n4_y = sc.nextInt();                                  int descSn12n2 = des2(n1_x, n2_x, n1_y, n2_y);                 int descSn12n3 = des2(n1_x, n3_x, n1_y, n3_y);                 int descSn12n4 = des2(n1_x, n4_x, n1_y, n4_y);                 int descSn22n3 = des2(n3_x, n2_x, n3_y, n2_y);                 int descSn22n4 = des2(n4_x, n2_x, n4_y, n2_y);                 int descSn32n4 = des2(n3_x, n4_x, n3_y, n4_y);                                  ArrayList<Integer> desList = new ArrayList<>();                 desList.add(descSn12n2);                 desList.add(descSn12n3);                 desList.add(descSn12n4);                 desList.add(descSn22n3);                 desList.add(descSn22n4);                 desList.add(descSn32n4);                                  Collections.sort(desList);                                  if (desList.get(0).equals(desList.get(1)) &&                         desList.get(1).equals(desList.get(2)) &&                         desList.get(2).equals(desList.get(3)) &&                         desList.get(4).equals(desList.get(5)))                 {                     System.out.println("Yes");                 }                 else                 {                     System.out.println("No");                 }                          }     }          public static int des2(int x1, int x2, int y1, int y2)     {             int desSquare = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);             return desSquare;     } } 【第二题有思路没时间写 不保证正确】 【思路】将题目转换成为两个二进制数相加再去重 import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         int n = sc.nextInt();                  Set <Integer> resultSet = new HashSet<>();                  for (int i=0; i<= (n+1)/2; i++)         {                 Integer a = i;                 Integer b = n - i;                                  String s1 = Integer.toBinaryString(a);                 String s2 = Integer.toBinaryString(b);                                  int i1 = Integer.parseInt(s1);                 int i2 = Integer.parseInt(s2);                                  Integer result = i1 + i2;                 resultSet.add(result);         }                  System.out.println(resultSet.size());     } } 本人菜鸡 可能有错误
点赞 评论

相关推荐

大世界中的渺小一棵:看出来你软硬都有基础,但是这样写简历软硬都擦边不知道你想投什么,建议针对岗位jd针对性修改下。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务