SRM 721 DIV2
来源:互联网 发布:python微信公众号开发 编辑:程序博客网 时间:2024/06/07 01:29
Single Round Match 721 Round 1 - Division II, Level One
代码如下:
public class FlightDataRecorder { public double getDistance(int[] heading, int[] distance) { double startx = 0, starty = 0; double dstx = 0, dsty = 0; for (int i = 0; i < heading.length; i++) { double radian = Math.PI * heading[i] / 180; dstx += distance[i] * Math.cos(radian); dsty += distance[i] * Math.sin(radian); } return Math.sqrt(Math.pow(startx - dstx, 2) + Math.pow(starty - dsty, 2)); }}
Single Round Match 721 Round 1 - Division II, Level Two
代码如下:
public class RememberWordsEasy { public String isPossible(int d1, int d2, int w1, int w2) { int mod = w1 % d1; int leftMin = w1 / d1; if (mod != 0) leftMin++; int leftMax = 0; if (w1 >=d1) leftMax = (2 * w1 / d1 + d1 - 1) / 2; else leftMax = (w1 + 1) / 2; int rightMin = (2 * w2 / d2 + 1 - d2) / 2; if (rightMin < 0) rightMin = 0; int rightMax = w2 / d2; //System.out.println("leftMin:" + leftMin + " leftMax:" + leftMax + " rightMin:" + rightMin + " rigthMax:" + rightMax); if ((rightMin>= leftMin && rightMin <= leftMax) || (rightMax>= leftMin && rightMax <= leftMax) || (rightMin - leftMin >= 0 && rightMin - leftMin <= 1) || (rightMax - leftMin >= 0 && rightMax - leftMin <= 1) || (rightMax - leftMax >= 0 && rightMax - leftMax <= 1) || (rightMin - leftMax >= 0 && rightMin - leftMax <= 1)) return "Possible"; return "Impossible"; }}
Single Round Match 721 Round 1 - Division II, Level Three
import java.util.*;public class ApocalypseEasy { private static List<Integer>[] adjList; private static Set<Integer> set = new HashSet<>(); private static Set<Integer> tokenSet = new HashSet<>(); private static boolean flag = false; public int maximalSurvival(int[] p, int[] position, int t) { int n = p.length; adjList = new List[n + 1]; for (int i = 0; i < n + 1; i++) { adjList[i] = new ArrayList<Integer>(); tokenSet.add(i); } for (int i : position) { tokenSet.remove(i); } set.clear(); for (int i : position) { set.add(i); } for (int i = 0; i < n; i++) { adjList[p[i]].add(i + 1); adjList[i + 1].add(p[i]); } int ans = 0; for (int u : position) { flag = false; boolean success = dfs(u, -1, t); if (success) ans++; } return ans; } private boolean dfs(int u, int p, int t) { if (t <= 0) { if (tokenSet.contains(u)) return true; return false; } for (Integer v : adjList[u]) { if (v == p) continue; if (set.contains(v)) { if(dfs(v, u, --t)) return true; } else if (tokenSet.contains(v)) { if (dfs(v, u, --t)) { if (!flag){ tokenSet.remove(v); flag = true; } return true; } } } if (tokenSet.contains(u)) return true; return false; }}
阅读全文
0 0
- SRM 721 DIV2
- SRM 114 DIV2 [550]
- SRM 398 DIV2 [250]
- SRM 399 DIV2 [250]
- SRM 387 DIV2 [250]
- SRM 387 DIV2 [600]
- SRM 397 DIV2 [500]
- SRM 400 DIV2 [250]
- SRM 400 DIV2 [500]
- SRM 397 DIV2 [1000]
- SRM 405 DIV2
- SRM 421Div2 500
- SRM 457 Div2 500
- SRM 465(DIV1 DIV2)
- SRM 465(DIV1 DIV2)
- SRM 481 div2
- SRM 212 div2
- SRM 430 div2
- Xpath初学
- 使用不同Console命令,调试JS更便捷
- 自定义控件那些事儿 ----- 一
- unpack requires a bytes object of length 4
- pgpool日志目录满会导致pgpool hang住 连接慢或超时
- SRM 721 DIV2
- 关于HOOK拦截函数的几种方法
- Qualcomm Android camera 架构简析及如何debug
- PropertyAnimation
- TensorFlow的张量与会话
- Enumeration和iterator
- UEditor 请求后台配置项http错误,上传功能将不能正常使用!
- 搭建SSH框架
- base64编码解码js