剑指Offer——网易笔试之不要二——欧式距离的典型应用_欧式距离计算例题

24 阅读2分钟

最后

推荐一些系统学习的途径和方法。

路线图

每个Web开发人员必备,很权威很齐全的Web开发文档。作为学习辞典使用,可以查询到每个概念、方法、属性的详细解释,注意使用英文关键字搜索。里面的一些 HTML,CSS,HTTP 技术教程也相当不错。

HTML 和 CSS:

html5知识

css基础知识

开源分享:docs.qq.com/doc/DSmRnRG… package cn.edu.ujn.nk;

import java.util.Scanner; import java.util.regex.Pattern;

/**

  • 2016-08-09 --01
  • 不要二
  • 二货小易有一个W*H的网格盒子,网格的行编号为0H-1,网格的列编号为0W-1。每个格子至多可以放一块蛋糕,任意两块蛋糕的欧几里得距离不能等于2。
  • 对于两个格子坐标(x1,y1),(x2,y2)的欧几里得距离为: ( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) )的算术平方根
  • 小易想知道最多可以放多少块蛋糕在网格盒子里。
  • 输入描述: 每组数组包含网格长宽W,H,用空格分割.(1 ≤ W、H ≤ 1000)
  • 输出描述: 输出一个最多可以放的蛋糕数
  • 输入例子: 3 2
  • 输出例子: 4
  • @author SHQ

*/ public class NotTwo {

/**

  • @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String str = in.nextLine(); if (str.length() == 0) { break; } Pattern pattern = Pattern.compile("[ ]+"); String[] arr = pattern.split(str); int w = Integer.parseInt(arr[0]); int h = Integer.parseInt(arr[1]);

System.out.println(notTwoGreed(h, w)); }

}

private static int notTwo(int h, int w) { int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if ((i / 2 + j / 2) % 2 == 0) cnt++; } } return cnt; } private static int notTwoGreed(int h, int w) { int [][] a = new int [h][w]; int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { // 左上 if(i< 2 && j < 2){ a[i][j] = 1; cnt++; // 右上 }else if(i < 2 && j-2 >= 0 && a[i][j-2] != 1){ a[i][j] = 1; cnt++; // 左下 }else if(j < 2 && i - 2 >= 0 && a[i-2][j] != 1){ a[i][j] = 1; cnt++; // 右下 }else if(i >= 2 && j >= 2 && a[i-2][j] != 1 && a[i][j-2] != 1){ a[i][j] = 1; cnt++; } } } return cnt; } }


 


### **美文美图**


 ![](https://p3-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/b91b2485bf0e45b99c55487d7e5f62dc~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAg55So5oi3MzM5MTQ5MjgwNjA=:q75.awebp?rk3s=f64ab15b&x-expires=1773142631&x-signature=ZQn%2Fb041rQIYWt%2Bq6yALmZCUClc%3D)



### 紧跟潮流



大前端和全栈是以后前端的一个趋势,懂后端的前端,懂各端的前端更加具有竞争力,以后可以往这个方向靠拢。

这边整理了一个对标“阿里 50W”年薪企业高级前端工程师成长路线,由于图片太大仅展示一小部分

**[开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://docs.qq.com/doc/DSmRnRGxvUkxTREhO)**

![](https://p3-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/4c3f8f50ce9147deb68fdecf7fece1a7~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAg55So5oi3MzM5MTQ5MjgwNjA=:q75.awebp?rk3s=f64ab15b&x-expires=1773142631&x-signature=AWCbm0Dx3xBHrUIY%2F6Fbw9hqmsg%3D)