摘要: 连号区间的性质是$\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) 编辑
摘要: 一种常用的方法是将「买入」和「卖出」分开进行考虑:「买入」为负收益,而「卖出」为正收益。在初入股市时,你只有「买入」的权利,只能获得负收益。而当你「买入」之后,你就有了「卖出」的权利,可以获得正收益。显然,我们需要尽可能地降低负收益而提高正收益,因此我们的目标总是将收益值最大化。因此,我们可以使用动 阅读全文
posted @ 2021-03-23 12:51 Dazzling! 阅读(48) 评论(0) 推荐(0) 编辑