摘要:
约瑟夫环,用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)
浙公网安备 33010602011771号