Codefroces B. New Skateboard】的更多相关文章

B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a…
题目链接:http://codeforces.com/contest/628/problem/B 题目大意:给你一段数字串s(1?≤?|s|?≤?3·10^5),求该字符串有多少子串是4的倍数.解题思路:很容易可以想到,如果一个两位数可以被4整除,那么在它左边加任何数字都能被4整除,如24能被4整除,那么124,1324也可以.因为第3位就是百位,只要是100的倍数肯定也是4的倍数.所以只用考虑前两位即可. 代码: #include<bits/stdc++.h> #define lc(a) (…
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a…
CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整除: 利用这个性质,先特判第一位数字是否能被4整除,可以则++cnt, 之后从第二位数字开始,设当前位为i,先判断a[i]能否被4整除,可以则++cnt, 再判断a[i-1]*10+a[i]能否被4整除,可以则cnt = cnt + (i) 相关证明: 设一整数各个位置为a1,a2,a3,...,an,b…
New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a cal…
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a…
B. New Skateboard 题目连接: http://www.codeforces.com/contest/628/problem/A Description Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask som…
  B. New Skateboard   time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He lef…
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a…
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a…
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to pre…
Codefroces 1328E Tree Querie 题目 给出一棵1为根,n个节点的树,每次询问\(k_i\) 个节点,问是否存在这样一条路径: 从根出发,且每个节点在这条路径上或者距离路径的距离为1 题解 由于是从根出发的路径,所以 距离这条路径的距离为1=这个点的父亲在路径上 本身就在根出发的这条路径上,当然这个点的父亲也在路径上 这样我们就把两个条件统一了,转化问题为: 是否存在一条从根出发的路径,使所有点都在这条路径上 根据从根出发的路径的特点,我们根据深度,从小到大排序,每次看后…
http://codeforces.com/contest/750/problem/D 题意:烟花会绽放n次,每次会向前推进t[i]格,每次绽放会向左右45°绽放,问有烟花的格子数. 思路:n = 30, t = 5,所以最多推进150格.范围很小,开一个300*300的数组,初始位置在(150, 150),直接BFS. #include <cstdio> #include <algorithm> #include <iostream> #include <cst…
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打.div1 >= 1900,div2 < 1900.求打完这n场比赛后可能得到的最大分数.如果无限大就输出"Inifinity",如果有矛盾就输出"Impossible". 思路:官方题解. For every contest we know that th…
time limit per testsecondsmemory limit per testmegabytesinputstandard inputoutputstandard outputPolycarp has quite recently learned about email aliases. Of course, he used to suspect that the case of the letters doesn't matter in email addresses. He…
题目大概说给一个数字组成的字符串问有几个子串其代表的数字(可以有前导0)能被4整除. dp[i][m]表示字符串0...i中mod 4为m的后缀的个数 通过在i-1添加str[i]字符转移,或者以str[i]为新后缀的开头转移 #include<cstdio> #include<cstring> using namespace std; ]; ][]; int main(){ scanf("%s",str); ; str[i]; ++i){ ++d[i][(st…
http://codeforces.com/gym/100781/attachments 题意:有N个点,M条边,问对两两之间的树添加一条边之后,让整棵大树最远的点对之间的距离最近,问这个最近距离是多少. 思路:一开始看成只有两个连通块,后来才注意到是多个连通块.DFS搜树上最长路径.答案有三种:第一种是添加了边之后,树的最长路径还是原来子树的路径,第二种是对子树长度进行排序后,两个最长的距离分别除以2向上取整后加上1.第三种比较难注意到,就是第二第三长的分别除以2向上取整后加上2,因为可能隔着…
题意翻译 给出一个数列,有q个操作,每种操作是把区间[l,r]中等于x的数改成y.输出q步操作完的数列. 输入输出格式 输入格式: The first line contains one integer n n n ( 1<=n<=200000 1<=n<=200000 1<=n<=200000 ) — the size of array a a a . The second line contains n n n integers a1 a_{1} a1​ , a2…
problem:一个圆上依次有1~2*n的数字.每个数字都有且只有另一个数字与他相连.选出三条线,使得每条线的两端之间隔的最少点(只包括被选择的6个点)的个数相等.输入输出格式输入格式: The first line contains integer n(3<=n<=10^5) — the number of lines. Each of the following n n n lines contains two integers ai​,bi​ (1<=ai,bi<=2n),…
Description两个人Van♂游戏.给出$n$个正整数$ai$两人轮流操作,每次选出一个素数$p$和一个幂数$k$,选择的前提为该$n$个数中有$p^{k}$的倍数.接着将所有的$p^{k}$的倍数除以$p^{k}$.变成新的序列,继续操作.不能操作者为败,问先手是否必胜.1≤100≤n,1≤ai≤109ExamplesInput41 1 1 1OutputArpa Input41 1 17 17OutputMojtaba Input41 1 17 289OutputArpa Input5…
Description给你一个长度为$n$的序列$A$.现在准许你删除任意一个数,删除之后需要修改最小的次数使序列单调递增.问最小次数.$1≤n≤200000$ExamplesInput55 4 3 2 1Output3Input51 2 8 9 5Output0 因为是修改形成递增,所以假设修改$l+1~r-1$,那么要求$a[r]-a[l]-1>=r-l-1$ 于是有$a[r]-r>=a[l]-l$ 于是就转化为求最长不下降子序列 因为可以删一个点,删掉的点的后面的值减去的位权-1 设$f…
Description定义$F(x)$为$F(x−1)$与$F(x−2)$的连接(其中$F(0)="0"$,$F(1)="1"$)给出一个长度为$n$的$01$字符串$s$,询问$s$在$F(x)$的所有子序列中出现了多少次.$1≤n≤100$$0≤x≤100$ExamplesInput2 411Output14Input10 1001010101010Output553403224 $f[i][l][r]$表示有多少$F[i]$的子序列里包含字符串[l,r] 有3…
A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. F…
[Description] 美丽数是指能被它的每一位非0的数字整除的正整数. [Input] 包含若干组数据,每组数据一行两个数n,m,表示求[n,m]之间的美丽数的个数. [output] 对于每组数据输出一个答案,各占一行. Input 11 9 Output 9 Input 112 15 Output 2 [Hit] 0 < n , m < 10^18 测试数据不超过100组 基本思路是用:dp[len][mod][lcm]表示<=len的长度中,此数为mod,各数位的最小公倍数为…
题目链接:http://codeforces.com/problemset/problem/628/B 解题思路: 一个数最后两位数能被4整除那么这个数就能被4整除,而且题目还是连续的子序列,这就很简单了 实现代码: #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> #include <queue>…
D题说的是 你选定一个区间如[l r] 将这个区间内的每个数都加上1,然后求将这整个整个序列都变成h的方案数有多少种 没有一个位置会有超过1次方[  或者放 ] 考虑当前位置放的是什么 有5种 - 不放 [ 右开区间 ] 左开区间 [] 自己一个区间 ][ 开始一个区间关闭一个区间 dp[i][open] 表示第i个位置被open个区间包括的方案数 可以知道 A[i]+open==h 或者等于 h-1 的时候是有解的因为自己可以产生一个 当A[i]+open==h时 不放 dp[i][open]…
C2 - Encryption (medium) 思路: 传统的dp: dp[i][j] 表示到第i个位置为止,分成j段的最大值 dp[i][j] = max(dp[l][j-1] + (sum[i] - sum[l]) % p) 0<= l < i 优化的dp: 我们发现n很大,但是p很小 于是 dp[i][j] 表示sum取模p后为i,分成j段的最大值 dp[i][j] = max(dp[l][j-1] + (sum[i] - l) % p) 0<= l < p 代码: #in…
找出递推关系式就好了 (fi+1)=(1  -1)(fi  ) (    fi)=(1   0)(fi-1) 不会打矩阵将就着看吧... 这是第一道矩阵快速幂.细节还是有很多没注意到的 本来想看挑战写的,结果上面的vector套vector看的我头都晕了.. #include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector&…
题目链接:http://codeforces.com/problemset/problem/735/D 题目大意:给一个n,n可以被分解成n1+n2+n3+....nk(1=<k<=n).要求出分解后n1~nk的最大因子(不包括本身)之和的最小值. 解题思路:看了别人的题解才知道是哥德巴赫猜想. 哥德巴赫猜想内容: ①所有大于2的偶数可以被分解成两个素数. ②所有大于7的奇数可以被分解成三个素数.(n-3)为偶数,3是一个素数,所以是三个. 现在来看这题,我们可以分两种情况: ①若n为偶数,则…
题目链接:http://codeforces.com/problemset/problem/919/D 题目大意:给你一张有向图,给你每个顶点上的字母和一些边,让你找出一条路径,路径上的相同字母数最多,输出最大相同字母数,若可以无穷多则输出-1(成环). 解题思路:因为是有向图,所以可以直接利用拓扑排序,拓扑排序过程中用f[i][j]记录到第i个点为止的路径,出现字母j的最大出现次数即可. 代码: #include<iostream> #include<cstdio> #inclu…