Bag of mice(CodeForces 148D )】的更多相关文章

D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains t…
题目链接 D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mounta…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains t…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains t…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies…
(CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output This is yet another problem dealing with regular bracket sequences. We should remind you t…
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进行一种特殊的排序,使得数组中相邻的两个数的差的绝对值成非递减趋势: 2.刚开始对这道题总是执拗于两个相等的数在不同位置,如何把它们放到前面这个问题,因为路走歪了,最终无果,没有思路.后来看了一些关于这道题的解题博客,豁然开朗. 3.使得数组中相邻的两个数的差的绝对值成非递减趋势,怎么想呢.单纯想怎么…
题目链接:http://codeforces.com/problemset/problem/558/C 题意:给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = ai*2 2.ai = ai/2,向下取整 思路: 可以除以二 或者 乘以二,就相当于位运算的右移和左移.用两个数组,vis 数组, cnt 数组.刚开始都初始化为0: vis[i] 表示 i 这个数可以由几个数转化而来,cnt[i] 表示题目给出的 n 个数全部转化为 i 需要的操作数. 首先遍历数…
题目链接:https://codeforces.com/problemset/problem/1197/D 题意: 给你一个序列,求一个子序列 a[l]~a[r] 使得该子序列的 sum(l,r)-k*(r-l+1)/m(向上取整)的值是在所有子序列中最大的,并输出最大值 思路: 法一:动态规划 dp[i][j] 表示序列到i截止,这一轮已经进行了j次取数(j = (len+m-1)%m) 那么dp[i][j]维护的就是起点为 s = i-j+1-m*t (t>=0)这个集合的最优,这样所有的…
题意 有n个黑帮(gang),每个黑帮有siz[i]个人,黑帮与黑帮之间有有向边,并形成了一个竞赛完全图(即去除方向后正好为一个无向完全图).在很多年前,有一些人参与了一次大型抢劫,参与抢劫的人都获得了一个真金条. 在这些年间,不同的黑帮之间进行了交易.具体过程是: 在时刻i,假如有一条边是u->v,那么u帮派中的i mod siz[u]号如果有金条(无论真假),并且v帮的i mod siz[v]没有任何金条,那么u中的这个人就会向v中的这个人一个假金条. 经过无数年的交易之后,各个帮派的金条拥…
Description You are given a positive integer nn. Let S(x) be sum of digits in base 10 representation of xx, for example, S(123)=1+2+3=6, S(0)=0. Your task is to find two integers a,ba,b, such that 0≤a,b≤n, a+b=n and S(a)+S(b) is the largest possible…
题意与分析 这题意思是这样的:在正方体的六面镶嵌给定颜色的宝石(相同颜色不区分),然后问最多有几种彼此不等价(即各种旋转过后看起来一致)的方案. 其实可以乱搞,因为范围只有720.求出全排列,然后每个旋转很多次,看看彼此可不可能相同,很多次旋转后都相同说明稳了,然后最后统计即可. 这题相当有意思的是复习了全排列的求法,竟然不能一下子想到- -||| 下面还会说下Java里面String与StringBuilder相关的内容:(待补) 代码 /* * ACM Code => cfr99c.java…
题意与分析 题意很简单,但是注意到小数可能有一千位,作为一周java选手的我选择了java解决. 这里的分析会归纳一些必要的Java API:(待补) 代码 /* * ACM Code => cf99a.java * Written by Sam X * Date: 三月, 19, 2019 * Time: 10:08 */ import java.util.*; import java.math.*; public class cf99a { public static void main(S…
学了kmp之后又学了hash来搞字符串.这东西很巧妙,且听娓娓道来. 这题的题意是:一个字符串如果是回文的,那么k值加1,如果前一半的串也是回文,k值再加1,以此类推,算出其k值.打个比方abaaba,k值为3,abaxxaba,k值为1.现在,给出一个串,让你求这个串的所有前缀(包括本身)的k值的和. 如果考虑马拉车,那么先预处理出每个地方的最长回文长度,然后不断的截断,如果子串的回文长度大于其回文长度,那么k值加1,这样即可.但是马拉车写起来比较繁琐,没有模板我也没法手写. 这里提供hash…
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to c…
题意: 袋子里有w个白球b个黑球,现在两个人轮流每次取一个球(不放回),先取到白球的获胜,当后手取走一个球时,袋子里的球会随机的漏掉一个,问先手获胜的概率. 分析: dp[i][j]表示袋子中i个白球j个黑球,先手取获胜的概率. 有四种情况 先手取到白球,获胜概率1.0*i/(i+j); 后手取到白球,先手输 前两次都取到黑球,漏掉一个黑球,转移到dp[i][j-3] 前两次都取到黑球,漏掉一个白球,转移到dp[i-1][j-2] #include <map> #include <set…
[题目大意] 给出一个$n$个数的序列$\{a_n\}$,其中有些地方的数为0,要求你把这个序列填成一个1到$n$的排列,使得: $(a_i, a_j) = 1$,当且仅当$(i, j) = 1$.多组数据. $n \leq 3\times 10^5, T\leq 10$ CodeForces:无多组数据,$n \leq 10^6$ [题解] 这题有点神奇啊.. 首先考虑序列全是0要怎么做. 考虑到如果两个数的位置含有的因数种类完全一样,那么它们是可以互换的.(这个挺显然的) 观察如果两个质数的…
题目链接:https://codeforces.com/problemset/problem/1202/D 题意: 构造一串只由 ‘1’,‘3’,‘7’ 组成的字符串,使其 ‘1337’ 子序列数量为n 思路: 构造 ‘13377733337’ 类型的字符串,使 C(m,2)+k=n k为中间 ‘7’ 的数量,C(m,2)为中间 ‘3’ 的数量 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define…
题意 给定两个\(P,Q\)的正整数区间(\(P,Q\)都符合\([L,R]\)这个区间,并且都\(\le 10^9\)),分别从其中随机选出一个数,选出的两个数作为一个新区间的左右端点.要求新区间内的幸运数刚好为\(k\)个的概率(幸运数指一个数的数位只有4或7). 分析 这题要思考着做.首先能有一个直觉:在\(10^9\)中间的幸运数肯定不多(2^10左右).这个可以暴力求出.然后概率如何求?所有的情况一定是\((P_r-P_l+1)(Q_r-Q_l+1)\)这么多,然后符合条件的幸运数区间…
题意: 对于给定的a[1..n],定义区间[s,t]和[x,y]"匹配"当且仅当下列条件同时满足:1. t-s=y-x,即长度相同.3. t<x或s>y,即两区间没有交.2. 对任0<=i<=t-s,有a[s]+a[x]=a[s+i]+a[x+i].现给出a[1..n]和Q个询问(x,y),求与[x,y]匹配的区间的个数. /* 写了n个小时,还没有调出来,Orz... 代码量倒是不大,但是细节巨多,已经弃疗了... 先差分一下, 然后题目就变成了,也就是这段区…
题意:给出一组排列,某些位置不知道(-1),要求求出有多少种还原方式,使得所有a[i]!=i /* 这是一道关于排列的动态规划,这种体大都可以当作棋盘来做,如果把i这个数放到第j个位置,那么就将棋盘的第i行第j列填入数字,最后使每一行每一列只有一个数. 我们从棋盘中删去已经填入数字的行和列,设删完后的棋盘为nn*nn,设mm为不能填数的位置数,f[i][j]代表i*i的棋盘有j个不能填数的位置的合法方案. 转移方程:f[i][j]=f[i][j-1]-f[i-1][j-1] 边界:f[i][0]…
You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R and x = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0. Input The only line contains six integers a1, b1, a2, b2, L, R (0 < a1, a…
题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.…
Vasya came up with a password to register for EatForces — a string ss. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits. But since EatForces takes care of the security of its users, user pas…
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has t…
题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 “R”.“G” 或 “B”. 求出更改初始字符串 s 中的最小字符数,以便更改后将有一个长度为 k 的字符串,该字符串是 s 的子字符串,也是无限字符串 “RGBRGBRGB…” 的子字符串 思路: 在无限字符串中有三种子串:“RGB...”,“GBR...”,“BRG...” 在这三种不同情况下,将所求字…
Description Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left. An 'R' indicates he should move one unit right. A 'U'…
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn nn numbers in a row, aiai is located in the ii-th position. She also has put a robot at each end of the row (to the left…
题意与分析 需要注意非法情况.换言之,合法情况其实很苛刻. 代码 /* * ACM Code => cf99b.java * Written by Sam X * Date: 三月, 19, 2019 * Time: 10:45 */ import java.util.*; import java.math.*; public class cf99b { public static void main(String args[]) { Scanner cin = new Scanner(Syst…
题意:有一个 n × m 的棋盘,每个点上标记了 L; R; X 中的一个 每次能选择一个没有被攻击过的点 (i; j),从这个点开始发射线,射线形状为: 1. 若字符是 L,向左下角和右上角发,遇到被攻击过的点就停下来 2. 若字符是 R,向左上角和右下角发,遇到被攻击过的点就停下来 3. 若字符是 X,向左小左上右下右上发,遇到被攻击过的点停下来 问先手是否必胜, n; m ≤ 20 /* 首先可以根据激光的性质,把图进行奇偶划分,然后就变成了两个子问题. 当出现一道激光时,这个游戏就变成了…