ST算法介绍:[转自http://blog.csdn.net/insistgogo/article/details/9929103] 作用:ST算法是用来求解给定区间RMQ的最值,本文以最小值为例 方法:ST算法分成两部分:离线预处理 (nlogn)和 在线查询(O(1)).虽然还可以使用线段树.树状链表等求解区间最值,但是ST算法要比它们更快,而且适用于在线查询. (1)离线预处理:运用DP思想,用于求解区间最值,并保存到一个二维数组中. (2)在线查询:对给定区间进行分割,借助该二维数组求最…
题目大意:给你两个长度为n的数组a, b,问你有多少个问你有多少个区间满足 a中最大值等于b中最小值. 思路:我本来的想法是用单调栈求出每个点的管辖区间,然后问题就变成了巨麻烦的线段覆盖问题,就爆炸写了 一晚上假算法.正解就是枚举一个端点,然后二分找右端点的区间,因为满足一个很神奇的单调性,然后st表维护 一下区间最值就好了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #def…
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <set> #include <map>…
题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图. 直接上一个DFS就搞定了 #include<cstdio> #include<set…
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to…
D. Friends and Subsequences 题目连接: http://www.codeforces.com/contest/689/problem/D Description Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their o…
C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from t…
B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n inter…
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fas…
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Mike wants to prepare for IMO but he doesn't know geometry, so…
D - Friends and Subsequences Description Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of…
C - Mike and Chocolate Thieves Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thie…
B - Mike and Shortcuts Description Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking fr…
A - Mike and Cellphone Description While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital eq…
最近迈克忙着考前复习,他希望通过出门浮躁来冷静一下.迈克所在的城市包含N个可以浮躁的地方,分别编号为1..N.通常迈克在家也很浮躁,所以说他家属于可以浮躁的地方并且编号为1.迈克从家出发,去一些可以浮躁的地方.迈克从第i个可以浮躁的地方到第j个可以浮躁的地方需要消耗abs(i-j)点精力.迈克花费的精力点数是这样算的,比如他去一组地方p1=1,p2,...,pk就需要点精力.当然,如果木有捷径的话走路会很无聊.无论两个地方相隔多远,走捷径的话迈克都只需要消耗1点精力.迈克所在的城市里由N条捷径.…
A.迈克和手机 当迈克在沙滩上游泳的时候,他意外的把他的手机扔进了水里.不过你甭担心因为他立马买了个便宜些的代替品,这个代替品是老款九键键盘,这个键盘只有十个等大的数字按键,按以下方式排列: 1 2 3 4 5 6 7 8 9 0 和他的老手机一起,他存在手机里的电话号码也都丢了.不过由于经常按,他能记住他输手机号的时候手指移动的路径.我们可以把他手指移动的路径看做一组连续的向量(就是可平移的那种),比如手指从5移动到8再移动到6,此时手指的动作和从2移动到5再移动到3是一样的.输入:第一行:一…
C 给出一个m 此时有 四个数 分别为x k*x k*k*x k*k*k*x k大于1 x大于等于1 要求求出来一个最小的值n 使其满足 这四个数中的最大值小于n 这四个数可能的组数为m 可以看出这四个数递增 所以最大值必定是第四个 所以我们二分n 需要注意的是longlong可以定义到1e18 初始应当是l小于等于可能的最小值(0) r大于等于可能的最大值(1e18) 如果初始范围就定义错误的话 二分不会出现正确答案 在这里由于控制l=mid+1或者r=mid-1 这一类的时候 容易丢失mid…
A - Mike and Cellphone 问有没有多解,每个点按照给出的序列用向量法跑一遍 #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> #include<map> using namespace std; ty…
A 脑筋急转弯 // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <cstdio> #include <cstring> #include <sstream> #include <string> #include <algorithm> #include <list> #incl…
E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry pro…
题目链接:传送门 题目大意:给你n个区间,求任意k个区间交所包含点的数目之和. 题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt与k的组合数) ans=ans+(len*C(cnt,k))%mod; #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorith…
B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight…
B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight…
A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bough…
解题关键:rmq模板题,可以用st表,亦可用线段树等数据结构 log10和log2都可,这里用到了对数的换底公式 类似于区间dp,用到了倍增的思想 $F[i][j] = \min (F[i][j - 1],F[i + 1 <  < (j - 1)][j - 1])$ #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath&…
st表很像线段树,但线段树既能查询和修改,而st表只能查询. 首先我们先用二维数组建立一个表,st[i][j]表内存的是从第i位开始1<<j范围内的best(st[i][j-1],st[i+(1<<j-1)][j-1]) 由上面的公式可知st[i][j]是由st[i][j-1],st[i+(1<<j-1)][j-1]更新而来的,我们可以将st[i][j]分成两段,由1<<j=2*(1<<j-1)可得一段是st[i][j-1],另一段则是st[i+…
1.0 SELECT语句用来从数据表中检索信息. SELECT what_to_select FROM which_table WHERE conditions_to_satisfy; what_to_select指出你想要看到的内容,可以是列的一个表,或*表示“所有的列”. which_table指出你想要从其检索数据的表. WHERE子句是可选项,如果选择该项,conditions_to_satisfy指定行必须满足的检索条件. 2.0 在我的博文“MySQL入门学习(八)”中,创建了一个小…
salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解   建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema Builder 或者build-->schema Builder进入: 2.采用force.com Explorer通过自己写查询语句来查询数据. 此链接为force.com Explorer的…
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q queries x1, -, xq on it. For each query xi you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, -, ar) = xi. 题目大意:…
预备知识 st表(Sparse Table) 主要用来解决区间最值问题(RMQ)以及维护区间的各种性质(比如维护一段区间的最大公约数). 树状数组 单点更新 数组前缀和的查询 拓展:原数组是差分数组时,可进行区间更新,单点查询,当然想区间查询也有办法(维护两个树状数组即可). 区别 树状数组用来维护一个具有区间可减(加)性质的工具,所以可以用来维护区间前缀和. 区间最值不具有区间可减性,所以不能使用树状数组进行维护,而使用st表. st表的思想 初始化 预处理数组, f[x][i] 表示区间[x…