摘要: 约瑟夫环,用lst来表示环(已经编过号),flag来标记是否出队(0为在队中,-1为出队了),t表示报数,p来遍历环,ans来记录环中剩余人数,剩最后一人就退出循环,遍历一遍flag输出最后一人的编号 `#include<stdio.h> include include using namespac 阅读全文
posted @ 2025-02-07 14:56 十柒* 阅读(18) 评论(0) 推荐(0)
摘要: 贪心思想,每次合并最小的两堆就能使总消耗最少,所以考虑优先对列,不过要从大到小。 `#include<stdio.h> include include using namespace std; int main(){ int n,a; priority_queue<int,vector,greate 阅读全文
posted @ 2025-02-07 14:50 十柒* 阅读(23) 评论(0) 推荐(0)
摘要: ST表模版题,用暴力显然超时,所以要采用倍增思想,把一个区间最大值转换成两个子区间的最大值,一直二分下去,直到变为单个值,这样维护一个dp[i][j],i为起始位置,j为2^j长度,这样每次查询的时间复杂度为O(1) `#include<stdio.h> include<stdlib.h> incl 阅读全文
posted @ 2025-02-07 14:48 十柒* 阅读(31) 评论(0) 推荐(0)
摘要: 优先队列模版题,没什么好说的 `#include<stdio.h> include<stdlib.h> include<string.h> include<bits/stdc++.h> using namespace std; int main(){ priority_queue q; char a 阅读全文
posted @ 2025-02-07 14:22 十柒* 阅读(8) 评论(0) 推荐(0)
摘要: 往返2x次可以看成到对岸2x次,也可以理解为2x只青蛙同时过河,所以每一个y区间石头高度和要>=2x,想到这一步后就解决了,只需要用双指针找出满足条件的最小的y区间了 `#include<stdio.h> include<stdlib.h> include<string.h> include<bit 阅读全文
posted @ 2025-01-26 15:22 十柒* 阅读(15) 评论(0) 推荐(0)
摘要: 这题用二分答案和贪心思想,为了让前面的人尽可能少的抄写,就从后往前分配任务,用贪心思想,先尽量分配任务,直到超过检验的x再分配给下一个人,最后判断人数是否满足条件,最后输出的时候也逆序输出就行了 `#include<stdio.h> include<stdlib.h> include<string. 阅读全文
posted @ 2025-01-26 15:16 十柒* 阅读(14) 评论(0) 推荐(0)
摘要: 显然用二分答案,重点就是check函数怎么写了,用x来表示套牌数,所以x要满足每一个x-a<=b,并且所有x-a的和要<=m.最后结果一定要开long long `#include<stdio.h> include<stdlib.h> include<string.h> include<bits/s 阅读全文
posted @ 2025-01-26 14:52 十柒* 阅读(34) 评论(0) 推荐(0)
摘要: 普通的二分答案,也没什么好说的 `#include<stdio.h> include<stdlib.h> include<string.h> include<bits/stdc++.h> using namespace std; struct bian{ int h; int w; }; int c 阅读全文
posted @ 2025-01-26 14:35 十柒* 阅读(28) 评论(0) 推荐(0)
摘要: 先将数列排序,A-B=C可以看成A=B+C,只要用二分把A的首位和末尾找到,A的个数就是差值+1,最后把每个数都求一遍就是答案了 `#include<stdio.h> include<stdlib.h> include<string.h> include<bits/stdc++.h> using n 阅读全文
posted @ 2025-01-26 14:28 十柒* 阅读(81) 评论(0) 推荐(0)
摘要: 就是基础的二分,没什么好说的 `#include<stdio.h> include<stdlib.h> include<string.h> int seek(int n,int *lst,int x){ int l=0,r=n-1; while(l<=r){ int m=(l+r)/2; if(ls 阅读全文
posted @ 2025-01-26 14:23 十柒* 阅读(17) 评论(0) 推荐(0)