二分查找
文章平均质量分 58
Prime me
Nobody can defeat me unless I don't want to win.
展开
-
图论小结(超详细)
文章目录1:最短路2:最小生成树3:最近公共祖先(LCA)1:最短路2:最小生成树3:最近公共祖先(LCA)原创 2022-02-09 21:27:56 · 665 阅读 · 0 评论 -
Monopoly(ccpc大学生程序竞赛补题)(前缀和加二分)
http://acm.hdu.edu.cn/showproblem.php?pid=7130第一步先求出前缀和和总和。判断sum值在不同情况下的处理情况。当sum==0,所有的数据只会在第一轮中出现一次。即若不在第一次中出现就不会出现。当sum<0时,将前缀和全部反转,并标记已翻转。将前缀和存入对应的取模后的map中进行存储,按照前缀和大小进行排序。然后二分查找若能找不到对应的取模值则输出-1,找到对应取模值后将前缀和值在数组中的位置取出。若取出值为最后,即为找不到对应值(只是对应的取模.原创 2021-11-08 19:03:37 · 257 阅读 · 0 评论 -
A Busiest Computing Nodes
You have a computing cluster with a total of k computing nodes, labelled from 0 to k−1. The cluster can handle multiple requests at the same time, but each node can process at most one request at the same time.The rules for request assignment to computin.原创 2021-09-24 16:47:31 · 108 阅读 · 0 评论 -
C. Slay the Dragon
Recently, Petya learned about a new game “Slay the Dragon”. As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of n heroes, the strength of t.原创 2021-09-21 18:49:54 · 529 阅读 · 0 评论 -
P2440 木材加工(二分)
题目描述木材厂有 nn 根原木,现在想把这些木头切割成 kk 段长度均为 ll 的小段木头(木头有可能有剩余)。当然,我们希望得到的小段木头越长越好,请求出 ll 的最大值。木头长度的单位是 \text{cm}cm,原木的长度都是正整数,我们要求切割得到的小段木头的长度也是正整数。例如有两根原木长度分别为 1111 和 2121,要求切割成等长的 66 段,很明显能切割出来的小段木头长度最长为 55。输入格式第一行是两个正整数 n,kn,k,分别表示原木的数量,需要得到的小段的数量。接下来 .原创 2021-09-12 16:58:35 · 432 阅读 · 0 评论 -
字符串哈希
定义字符串的哈希算法,就是将一个字符串,转化成整数原来我们进行字符串匹配的时候,就是按照字母去匹配,那么时间复杂度是o(n)。如果转化成数字,去匹配那么时间复杂度会变成o(1),当两个数字相同时就会判定两个字符串相等。例题1:统计难题Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).Input输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的原创 2021-09-10 21:00:27 · 101 阅读 · 0 评论 -
二分查找操作使在数组和vector中的使用
#include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){ vector<int> s= {1,2,3,4,5,6,7,8,9,0,3,2,1111}; int b=binary_search(s.begin(),s.end(),5);//查找成功,返回1 cout<<"在vector中查找元素5,结果为:原创 2021-09-10 16:32:02 · 105 阅读 · 0 评论 -
Almost Sorted Array(最长上升子序列o(nlogn))
We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. But sometimes it is an overkill to use these algorithms for an almost sorted array.We say an array is sorted if its elements.原创 2021-07-31 22:01:54 · 126 阅读 · 0 评论