wolves 3 mesi fa
parent
commit
5297b42c6e
4 ha cambiato i file con 62 aggiunte e 0 eliminazioni
  1. 8 0
      25/12/1351.cpp
  2. 22 0
      25/12/comp/28q1.cpp
  3. 15 0
      25/12/comp/28q2.cpp
  4. 17 0
      25/12/comp/28q3.cpp

+ 8 - 0
25/12/1351.cpp

@@ -0,0 +1,8 @@
+#include <vector>
+
+class Solution {
+public:
+    int countNegatives(std::vector<std::vector<int>>& grid) {
+        
+    }
+};

+ 22 - 0
25/12/comp/28q1.cpp

@@ -0,0 +1,22 @@
+#include <algorithm>
+#include <climits>
+#include <vector>
+class Solution {
+public:
+    long long maximumScore(std::vector<int>& nums) {
+        std::vector<long long> pre;
+        int n = nums.size();
+        long long sum = 0;
+        for (int i = 0; i < n; i++) {
+            sum += nums[i];
+            pre.push_back(sum);
+        }
+        int mins = nums[n - 1];
+        long long ans = pre[n-2] - mins;
+        for (int i = n - 3; i >= 0; i--) {
+            mins = std::min(mins,nums[i+1]);
+            ans = std::max(ans,pre[i] - mins);
+        }
+        return ans;
+    }
+};

+ 15 - 0
25/12/comp/28q2.cpp

@@ -0,0 +1,15 @@
+#include <algorithm>
+class Solution {
+public:
+    long long minimumCost(int cost1, int cost2, int costBoth, int need1, int need2) {
+        if (costBoth >= cost1 + cost2) {
+            return (long long)cost1 * need1 + (long long)cost2 * need2;
+        }
+        int m1 = std::min(need1,need2);
+        long long a2 = (long long)std::max(need1,need2) * costBoth;
+        long long ans = (long long)m1 * costBoth;
+        ans += (long long)(need1 - m1) * cost1;
+        ans += (long long)(need2 - m1) * cost2;
+        return std::min(ans,a2);
+    }
+};

+ 17 - 0
25/12/comp/28q3.cpp

@@ -0,0 +1,17 @@
+class Solution {
+public:
+    int minAllOneMultiple(int k) {
+        if (k%2==0 || k%5==0) {
+            return -1;
+        }
+        int remainder = 1;
+        for (int i = 1 ;i<=k;i++) {
+            if (remainder % k == 0) {
+                return i;
+            }
+            // (a * 10 + 1) % k = ((a % k) * 10 + 1) % k
+            remainder = (remainder * 10 + 1) % k;
+        }
+        return -1;
+    }
+};

备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。