上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 67 下一页
摘要: 水题。 const int N=10010; int n; bool check(int x) { bool ok=false; while(x) { int t=x%10; if(t == 2 || t == 0 || t == 1 || t == 9) ok=true; x/=10; } ret 阅读全文
posted @ 2021-03-24 10:49 Dazzling! 阅读(26) 评论(0) 推荐(0) 编辑
摘要: 二分做法 考虑到$A_i < B_j < C_k$,如果以$A_i$为基准进行二分,时间复杂度为:\(O(n^2log^2n)\)。 若以$B_j$为基准,则只需在$A$数组中查找最后一个小于$B_j$的位置,以及$C$数组中查找第一个大于$B_j$的位置,时间复杂度为:\(O(nlogn)\)。 阅读全文
posted @ 2021-03-24 10:45 Dazzling! 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 哈希表中 \(s[r]\) 的计数加一, 同时将指针 \(r\) 向后移一位 不断向后移动 \(l\),直至区间 $[l,r-1]$中 \(s[r-1]\) 的个数等于1为止; class Solution { public: int lengthOfLongestSubstring(string 阅读全文
posted @ 2021-03-24 09:49 Dazzling! 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 连号区间的性质是$\max a[l \sim r] - \min a[l \sim r] == r-l$。 const int N=10010; int a[N]; int n; int main() { cin>>n; for(int i=0;i<n;i++) cin>>a[i]; int res 阅读全文
posted @ 2021-03-23 23:27 Dazzling! 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 分情况讨论即可。 以感染蚂蚁向右走为例,对每一个蚂蚁的走向: 右边向左走,必然被感染 右边向右走,必然不会被感染 左边向左走,必然不会被感染 左边向右走: 右边存在向左走,则必然被感染 右边不存在向左走,则必然不会被感染 const int N=55; int d[N]; int n; int ma 阅读全文
posted @ 2021-03-23 21:43 Dazzling! 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 水题。 int n; int main() { cin>>n; int res=n; int carry=0; while(n) { n+=carry; carry=n%3; n/=3; res+=n; } cout<<res<<endl; //system("pause"); return 0; 阅读全文
posted @ 2021-03-23 21:15 Dazzling! 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 设第一项为$x_1$,则$2 \sim n$项依次为$x_1+dif_1、x_1+dif_1+dif_2、\cdots、x_1+dif_1+dif_2+\cdots+dif_$。其中$dif_i \in {+a,-b}$,即第$i$项为:\(x_1+(i-1)*dif_i\)。 则总和为:\(sum 阅读全文
posted @ 2021-03-23 21:06 Dazzling! 阅读(41) 评论(0) 推荐(0) 编辑
摘要: 注意只有连续$k$个或更多坐标均位于矩形内(含边界),则认为该居民曾在高危区域逗留。 const int N=25; int n,k,t,xld,yld,xru,yru; int pass,stay; bool check(int x,int y) { return x>=xld && x<=xru 阅读全文
posted @ 2021-03-23 17:25 Dazzling! 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 水题。 const int N=210; PII dist[N]; int n,x,y; int get(int a,int b,int c,int d) { return (a-c)*(a-c)+(b-d)*(b-d); } int main() { cin>>n>>x>>y; for(int i 阅读全文
posted @ 2021-03-23 17:11 Dazzling! 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 和122. 买卖股票的最佳时机 II状态定义一模一样。 转移方程如下: \[ f(i,0) = \max(f(i-1,0),f(i-1,1)+prices[i]-fee); \\ f(i,1) = \max(f(i-1,1),f(i-1,0)-prices[i]); \] class Solutio 阅读全文
posted @ 2021-03-23 13:01 Dazzling! 阅读(17) 评论(0) 推荐(0) 编辑
上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 67 下一页