力扣 第 208 场周赛
今晚剩一个小时左右了emmmm能写多少写多少哈,
并且小白做题慢,还要参考大佬的题解优化emmmmm肯定做不完呐呐呐(我才不会说是因为我不会做呢)
那,就开始咯~
模拟一下栈的思路,,还行吧
就是,,一开始想多了,想匹配所有字符emmmm关键/还涉及转制
俺还写了测试主函数emmmm
1 #include <iostream> 2 #include <stdio.h> 3 #include <stack> 4 #include <vector> 5 #include <math.h> 6 #include <string> 7 #include <algorithm> 8 #include <unordered_map> 9 #include <map> 10 #include<set> 11 #include <cstring> 12 #include <queue> 13 14 #include <stdio.h> 15 #include <stdlib.h> 16 #define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) 17 18 #define ll long long 19 20 using namespace std; 21 22 class Solution { 23 public: 24 int minOperations(vector<string>& logs) { 25 stack<int> st; 26 for (int i = 0; i < logs.size(); ++i) { 27 if(logs[i][0]=='.' && logs[i][1]=='.'){ 28 while(!st.empty()) 29 st.pop(); 30 } 31 else if(logs[i][0]=='.'){ 32 33 } 34 else{ 35 st.push(1); 36 } 37 38 } 39 return st.size(); 40 } 41 }; 42 int main(){ 43 Solution s; 44 vector<string> v={"d1/","d2/","../","d21/","./" 45 }; 46 cout<<s.minOperations(v); 47 }
读题读了半天,幸亏不是英文的
就是个模拟嘛,然而心态在这一刻还是崩溃了
具体是为啥呢,emmmmm看了看样例发现,其实在中间有可能游客数为0后面还有人
我限制写少了...
这就对了呐呐
我写的main函数检测第130个样例,,,,,,
大佬有手就行的题本小白得研究好久........
#include <iostream> #include <stdio.h> #include <stack> #include <vector> #include <math.h> #include <string> #include <algorithm> #include <unordered_map> #include <map> #include<set> #include <cstring> #include <queue> #include <stdio.h> #include <stdlib.h> #define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define ll long long using namespace std; class Solution { public: int minOperationsMaxProfit(vector<int>& customers, int boardingCost, int runningCost) { int res = 0; int finres = 0; int times = 0; int fintimes = 0; int num = 0; int s=customers.size(); for (int i=0;;i++) { if(i!=0 && num == 0) break; times++; if(i<s) { num += customers[i]; } if (num >= 4) { res += (4 * boardingCost - runningCost); num -= 4; } else { res += (num * boardingCost - runningCost); num = 0; } if (res > finres) { finres = res; fintimes = times; } cout<<finres<<" "<<fintimes<<endl; } return finres ? fintimes : -1; } }; int main(){ Solution s; vector<int> v={2,16,22,15,46,10,23,0,13,23,33,14,21,19,47,6,13,28,37,18,7,44,25,11,35,10,12,37,27,16,18,48,41,23,22,14,50,39,14,15,26,9,6,13,24,18,36,50,16,33,13,27,11,37,25,18,21,39,41,1,47,44,39,8,40,40,8,0,5,25,44,24,0,27,15,1 }; int a=88,b=6; cout<<s.minOperationsMaxProfit(v,a,b); }
困了,不知能撑多久
第三题不想看了,太长了,等我咕咕咕
这网速有点不太好
1 class Solution { 2 int max_satisfied = 0; 3 public: 4 int maximumRequests(int n, vector<vector<int>>& requests) { 5 vector<int> count(n, 0); 6 dfs(requests, count, 0, 0); 7 return max_satisfied; 8 } 9 void dfs(vector<vector<int>>& requests, vector<int>& count, int idx, int satisfied) 10 { 11 if(satisfied+requests.size()-idx <= max_satisfied) 12 return;//剩余的假如都可以满足,都不可能超过最大的,剪枝 13 if(idx == requests.size()) 14 { 15 for(int i = 0; i < count.size(); i++) 16 { 17 if(count[i] != 0) 18 return; 19 } 20 max_satisfied = max(max_satisfied, satisfied); 21 return; 22 } 23 24 int from = requests[idx][0], to = requests[idx][1]; 25 count[from]--; 26 count[to]++; 27 dfs(requests, count, idx+1, satisfied+1);//选 28 count[from]++; 29 count[to]--; 30 dfs(requests, count, idx+1, satisfied);//当前不选 31 } 32 };
呐呐呐网速不想让我写了,待我回来更三.
为了自己,和那些爱你的人