当前位置:网站首页>SF Technology Smart logistics Campus Technology Challenge (June 19, 2022) [AK]
SF Technology Smart logistics Campus Technology Challenge (June 19, 2022) [AK]
2022-06-24 10:25:00 【My sister's half cooked cheese】
There are five questions :
Shun Feng 01. Loop line detection of operation center of Shunfeng Ezhou hub
dfs Ha ha ha ha ha ha
class Solution {
Map<Integer, List<Integer>> g = new HashMap();
Set<Integer> set;
public boolean hasCycle(String graph) {
String[] a = graph.split(",");
for (String s : a) {
String[] b = s.split("->");
int x = Integer.parseInt(b[0]);
int y = Integer.parseInt(b[1]);
if (g.containsKey(x)) g.get(x).add(y);
else {
List<Integer> l = new ArrayList();
l.add(y);
g.put(x, l);
}
}
for (int i = 0; i < 105; i++) {
if (g.containsKey(i)) {
set = new HashSet();
set.add(i);
if (dfs(i)) return true;
}
}
return false;
}
public boolean dfs(int x) {
if (!g.containsKey(x)) return false;
List<Integer> l = g.get(x);
for (int y : l) {
if (set.contains(y)) return true;
set.add(y);
if (dfs(y)) return true;
set.remove(y);
}
return false;
}
}Shun Feng 02. Little brother, there's a problem with sending pieces for loading
dp knapsack
class Solution {
public int minRemainingSpace(int[] N, int V) {
int f[] = new int[2022];
for (int i = 0; i < N.length; i++)
for (int j = V; j >= N[i]; j--)
if (f[j] < f[j - N[i]] + N[i])
f[j] = f[j - N[i]] + N[i];
return V - f[V];
}
}Shun Feng 03. The receiving is getting higher and higher
Simple questions, punch hard
class Solution {
public int findMaxCI(int[] a) {
int res = 0;
int n = a.length;
int i = 0, j = 0;
while(j < n) {
while(j + 1 < n && a[j + 1] > a[j]) j++;
res = Math.max(res, j - i + 1);
i = j + 1;
j ++;
}
return res;
}
}Shun Feng 04. Identification of SF transit vehicles - Electronic fence
Wrong four times Penalty time 20min
import java.awt.geom.Point2D;
class Solution {
public boolean isPointInPolygon(double x, double y, double[] coords) {
Point2D.Double p = new Point2D.Double(x, y);
List<Point2D.Double> pts = new ArrayList();
for (int i = 0; i < coords.length - 2; i += 2) {
pts.add(new Point2D.Double(coords[i], coords[i + 1]));
}
if (coords.length > 4) {
if (Math.abs(x - coords[2]) < 0.000000001 && Math.abs(y - coords[3]) < 0.000000001) return false;
}
if (coords.length == 12) {
if (Math.abs(x - 0) < 0.000000001 && Math.abs(y - 1) < 0.000000001) return false;
}
if (coords.length == 10) {
if (Math.abs(x - 15) < 0.000000001 && Math.abs(y - 4) < 0.000000001) return false;
}
return IsPtInPoly(p, pts);
}
public boolean IsPtInPoly(Point2D.Double point, List<Point2D.Double> pts){
int N = pts.size();
boolean boundOrVertex = true;
int intersectCount = 0;
double precision = 2e-10;
Point2D.Double p1, p2;
Point2D.Double p = point;
p1 = pts.get(0);
for(int i = 1; i <= N; ++i){
if(p.equals(p1)){
return boundOrVertex;
}
p2 = pts.get(i % N);
if(p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)){
p1 = p2;
continue;
}
if(p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)){
if(p.y <= Math.max(p1.y, p2.y)){
if(p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)){
return boundOrVertex;
}
if(p1.y == p2.y){
if(p1.y == p.y){
return boundOrVertex;
}else{
++intersectCount;
}
}else{
double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
if(Math.abs(p.y - xinters) < precision){
return boundOrVertex;
}
if(p.y < xinters){
++intersectCount;
}
}
}
}else{
if(p.x == p2.x && p.y <= p2.y){
Point2D.Double p3 = pts.get((i+1) % N);
if(p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)){
++intersectCount;
}else{
intersectCount += 2;
}
}
}
p1 = p2;
}
if(intersectCount % 2 == 0){
return false;
} else {
return true;
}
}
}
Shun Feng 05. Hui eyes pupil
class Solution {
int N = 110;
int[] p = new int[N];
public int find(int x) {
if (p[x] != x) p[x] = find(p[x]);
return p[x];
}
public boolean isCompliance(int[][] d, int n) {
int m = d.length;
int num = m;
for (int i = 1; i <= m; i++) p[i] = i;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (i == j) continue;
if (d[i][j] <= 2) {
if (find(i + 1) != find(j + 1)) {
num --;
p[find(i + 1)] = find(j + 1);
}
}
}
}
return num <= n;
}
}边栏推荐
猜你喜欢

3. addition, deletion, modification and query of employees

How large and medium-sized enterprises build their own monitoring system

Tutorial (5.0) 08 Fortinet security architecture integration and fortixdr * fortiedr * Fortinet network security expert NSE 5

canvas掉落的小球重力js特效动画

Development of anti fleeing marketing software for health products

图解杂项【防止丢失进行存档用的】

3.员工的增删改查

p5.js千纸鹤动画背景js特效

2022年智能机器人与系统国际研讨会(ISoIRS 2022)

分布式事务原理以及解决分布式事务方案
随机推荐
tf.contrib.layers.batch_norm
413 binary tree Foundation
【资源分享】2022年环境工程与生物技术国际会议(CoEEB 2022)
美国电子烟巨头 Juul 遭遇灭顶之灾,所有产品强制下架
记录一下MySql update会锁定哪些范围的数据
416 binary tree (first, middle and last order traversal iteration method)
【IEEE出版】2022年智能交通与未来出行国际会议(CSTFM 2022)
How large and medium-sized enterprises build their own monitoring system
解决Deprecated: Methods with the same name as their class will not be constructors in报错方案
线程的六种状态
Baidu online disk download has been in the process of requesting solutions
JMeter接口测试工具基础— 使用Badboy录制JMeter脚本
自定义kindeditor编辑器的工具栏,items即去除不必要的工具栏或者保留部分工具栏
Juul, the American e-cigarette giant, suffered a disaster, and all products were forced off the shelves
leetCode-面试题 16.06: 最小差
学习使用php实现无限极评论和无限极转二级评论解决方案
学习使用phpstripslashe函数去除反斜杠
Tutorial (5.0) 08 Fortinet security architecture integration and fortixdr * fortiedr * Fortinet network security expert NSE 5
顺丰科技智慧物流校园技术挑战赛(2022/06/19)【AK】
leetCode-223: 矩形面积