
一些常用技巧
颜之年
这个作者很懒,什么都没留下…
展开
-
取模和快速幂
有时需要计算一个特别大的数,结果是取模的,但是中间过程可能超出long long等上限,因此可以根据计算过程中可以进行取模的性质,采用快速幂运算来计算(ab) mod M=(a mod M)(b mod M) mod M;(a+b) mod M=(a mod M+b mod M) mod M;(a/b) mod M=(a*b^(M-2)) mod M;(费马小定理)#def...原创 2020-04-12 17:08:18 · 209 阅读 · 0 评论 -
二分搜索的使用技巧
1.搜索第一个等于key或第一个大于key的值比如1 ,2,3,3,3,4中,若key为3,则取第一个3int binarySearch1(int arr[], int left, int right, int key) //第一个>=key{ int mid; while (left <= right) { mid = ( left + right ) / 2; ...原创 2020-04-12 16:29:20 · 288 阅读 · 0 评论 -
poj3061-subsequence
二分法时间复杂度O(nlogn)尺取法时间复杂度O(n)#include <iostream>#include <algorithm>using namespace std;#define N 100010int arr[N+10];//int sum[N+10];int main(){ //二分法 /*int cases; int n, s; ci...原创 2018-03-08 21:19:35 · 268 阅读 · 1 评论 -
Problem - 1118B - Codeforces(Tanya and Candies)
这是Codeforces Round #540 (Div. 3)的第二题,所以题目难度适中,题目如下:题目链接:https://codeforces.com/contest/1118/problem/BTanya hasncandies numbered from1ton. Thei-th candy has the weightaiai.She plans to eat ...原创 2019-02-28 17:26:04 · 460 阅读 · 0 评论 -
poj1002 487-3279
Time Limit:2000MS Memory Limit:65536K Total Submissions:315192 Accepted:56155 Description企业喜欢用容易被记住的电话号码。让电话号码容易被记住的一个办法是将它写成一个容易记住的单词或者短语。例如,你需要给滑铁卢大学打电话时,可以拨打TUT-GLOP。有时,只将...原创 2019-03-15 18:25:27 · 247 阅读 · 0 评论 -
poj2503 Babelfish (hashmap)
题目链接:http://poj.org/problem?id=2503该题用hashmap可以解决,我从中学到了以下几点:1. 链表插入可以倒着来,省去搜索到链表末尾再进行插入的时间,代码如下p->next = link[e]; //link[]一开始被赋予nullptrlink[e] = p;2. gets_s函数当读到文件结束符时返回nullptr,可以在控制台使用ct...原创 2019-03-17 13:35:40 · 232 阅读 · 0 评论