CodeForces 468A Program F】的更多相关文章

Description Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game. Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote…
Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Input The first line contains a single integer nn (2≤n≤150000) — the number of kittens. Each of the following n−1lines contains integers xi and yi (1≤xi,…
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) 的方案数 \(mod 1e9 + 7\), 走的规则和限制如下: From the cell (i, j) you may advance to: (i - 1, j + 1) - only if i > 1, (i, j + 1), or (i + 1, j + 1) - only if i <…
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F Description Doomsday comes in t units of time. In anticipation of such a significant event n people prepared m vaults in which, as they think, it will…
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Description We all know that King Triton doesn't like us and therefore shipwrecks, hurricanes and tsunami do happen. But being bored with the same routine…
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/F Description I Ilya Muromets is a legendary bogatyr. Right now he is struggling against Zmej Gorynych, a dragon with n heads numbered from 1 to nf…
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同时消去,问最少需要消去多少次 题解 定义dp[l][r]为区间[l,r]剩下一个字符所需要的最小次数 dp[l][r]=min(dp[l][i]+dp[i+1][r]+x) x为消去剩下两个字符所需要的次数,假如两个字符相同需要x=-1 代码 #include<bits/stdc++.h> #de…
https://codeforces.com/contest/1051/problem/F 题意 给一个带权联通无向图,n个点,m条边,q个询问,询问两点之间的最短路 其中 m-n<=20,1<=n,m<=1e5 思路 因为图一定联通,所以n-1<=m<=n+20 因为是求任意两点的最短路,所以直接暴力跑最短路是不行的,考虑选择性的跑最短路 因为是求两点之间的距离,所以可以往lca方面想 先跑一棵生成树出来,然后处理出每个点的lca,这样就可以求出任意两点的距离 然后就可以记…
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/F Description I Ilya Muromets is a legendary bogatyr. Right now he is struggling against Zmej Gorynych, a dragon with n heads numbered from 1 to nf…
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a is divisible by another integer b, then b is called the divisor of a. For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12. Let's def…
链接:http://codeforces.com/contest/616 A题: 统一成1e6长度的字符串,右对齐比较字典序. B题: 求所有行的最小值,里面最大的那个.暴力. C题: 先用dfs给每个位置标记一个连通块编号.然后对于每个*,直接看一下上下左右合并一下(不是真的合并)看一下大小. D题: 用map维护一下每种数字出现的次数,从左到右枚举左端点,右端点是决策单调的.双指针O(n)扫一遍. E题: $n \mod i = n - [\frac{n}{i}]*i$ F题: 待补.…
链接:http://codeforces.com/contest/612/ A题: 枚举切多少个p,看剩下的能否整除q. B题: 从1到n模拟一下,累加移动的距离. C题: 先用括号匹配的思路看是否有解(所有左括号看做一样,所有右括号看做一样). 如果有解,就从左到右扫描,记录一个栈,遇到跟栈顶不匹配的右括号就替换一次. D题: 扫描线做一遍得到初步结果.然后合并一下初步结果得到最终结果. E题: 一个排列可以看成若干个环,一个排列的平方就是,奇数长度的环做了一次置换,偶数长度的环拆成了两个.所…
链接:http://codeforces.com/contest/600 A题: 字符串处理. B题: sort+upper_bound C题: 统计一下每种字符的个数,然后贪心. (1) 如果没有奇数个的字母.直接按字典序放. (2) 如果有1个奇数个的字母.就把单出来的那一个字符(注意是一个字符,不是所有的那种字母)放中间,其他的按字典序放. (3) 如果多与1个奇数个的字母.就把单出来的每种字母的一个按字典序排好,最右边的替换成最左边的,次右边的替换成次左边的……最后情况会转变为(1)或者…
题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/7282909.html    由于新生成的m+1个数列第一个肯定为0,所以可以忽略掉,当作每次新生成的数列只拥有m个元素    来枚举一个例子,可以发现规律. 当a[] = {1,0,0,0,0}时,手动推出的矩阵如下: 可以发现对于这个矩阵显然是满足杨辉三角的,我们二分出一个值后可以直接利用组合数来…
F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a matrix A of size n × n. Let's call the matrix with nonnegative elements magic if it is symmetric (so aij = aji), aii = 0 and aij ≤ max(aik, ajk) for all…
F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given an array with n integers ai and m queries. Each query is described by two integers (lj, rj). Let's define the function . The function is defined for o…
F. The Sum of the k-th Powers 题目连接: http://www.codeforces.com/contest/622/problem/F Description There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees. Find the value of the sum modulo 109 + 7 (so you shoul…
F. Bear and Fair Set 题目连接: http://www.codeforces.com/contest/628/problem/F Description Limak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's very unfortunate for you. He will eat all your coo…
题目链接:http://codeforces.com/problemset/problem/691/F 题目大意:给定n个数,再给m个询问,每个询问给一个p,求n个数中有多少对数的乘积≥p 数据范围:2≤n≤10^6, 1≤ai≤3*10^6,1≤m≤10^6, 1≤p≤3*10^6 解题思路:比赛的时候比较naive的思路是把n中的数字排序去了重之后,对于每个p,最多枚举√p步,就能得到答案.而这个naive的思路是O(p√p)的,结果T了. 后来百思不得其解,去看了官方的解答.感觉是一种很有…
interlinkage: http://codeforces.com/contest/1119/problem/F description: 有一颗$n$个节点的树,每条边有一个边权 对于一个$x$,删去一些边使得每个点的度数都不超过$x$,最小化删去边的边权并输出 需要一次输出$x=0->n-1$的值 $1<=n<=250000$ solution: part1 先考虑单个$x$的做法.任选一个根,设$f_{u,0/1}$表示以节点$u$为根的子树内,节点$u$与它的父亲不断/断的最…
题目链接:http://codeforces.com/problemset/problem/977/F 题意:给你一串数字序列,让你求最长上升子序列,但是这个子序列呢,它的数字得逐渐连续挨着. 题解:LIS的求法去做嘛.经典dp,处理的时候记录一下最大起点的下标,然后在最后循环找的时候,对比一下当前的值是否在逐渐+1即可. 坑点大概就是会RE.QAQ就是开不下dp的数组了嘛. #include<iostream> #include<vector> #include<map&g…
F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output There are n frogs sitting on the coordinate axis Ox. For each frog two values xi, ti are known — the position and th…
F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course…
题目链接:http://codeforces.com/problemset/problem/468/A 题目意思:给出一个数n,利用 1 - n 这 n 个数,每个数只能用一次,能否通过3种运算: +.-.* 使得最后的结果为24. 首先大方向想得是对的,就是用前面尽量连续的数构成24,而后面就通过相互抵消变成0,这样就不会影响到前面算出的结果. 但有两个地方比较致命,所以最终要看着test的数据改--.首先没有留意到 n 个数操作的次数恰好为 n - 1 次!!(之前千辛万苦找到构成24的方法…
F. A Heap of Heaps time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final tes…
#451 Div2 F 题意 给出一个由数字组成的字符串,要求添加一个加号和等号,满足数字无前导 0 且等式成立. 分析 对于这种只有数字的字符串,可以快速计算某一区间的字符串变成数字后并取模的值,首先从右到左,将字符串转化为数字并取模,那么 \(h[i]\) 表示字符串 \(S[i...len]\) 转化成数字后并取模的值,如果要求区间 \([i, j]\) 所表示的数字是多少,首先求出 \(h[i] - h[j + 1]\),后面的 0 可以除掉,求一下逆元即可. 然后枚举一下,比一下就行了…
#452 Div2 F 题意 给出一个字符串, m 次操作,每次删除区间 \([l,r]\) 之间的字符 \(c\) ,输出最后得到的字符串. 分析 通过树状数组和二分,我们可以把给定的区间对应到在起始字符串上的区间. 然后暴力去删字符即可(因为最多只会删掉等同于字符串长度的字符个数),总共只有 62 种字符,set 维护下位置. code #include<bits/stdc++.h> using namespace std; typedef long long ll; const int…
Description 题面 有\(2*n\)的时间,去煎一块肉,肉有两面,你需要在特定的时间内翻转,使得每一面都恰好煎了\(n\)分钟,你有\(k\)次翻转的机会,每一次表示为一段时间 \([L_i,R_i]\),你可以在区间内翻转任意次, 保证区间不相交 问是否存在合法的方案使得两面恰好都只煎了 \(n\) 分钟,并输出最小翻转次数 \(n<=100000,k<=100\) Solution 容易想到一个DP,设 \(f[i][j]\) 表示一共煎了 \(i\) 分钟,当前这一面煎了 \(…
FallDream dalao找的插值练习题 题目大意:给定n,k,求Σi^k (i=1~n),对1e9+7取模.(n<=10^9,k<=10^6) 思路:令f(n)=Σi^k (i=1~n),则有f(n)-f(n-1)=n^k,说明f(n)的差分是n的k次多项式,则所求f(n)为n的k+1次多项式,利用拉格朗日插值公式,我们暴力计算n=0~k+1时的答案,代入公式,利用预处理的信息加速计算,总复杂度O(klogMOD). #include<cstdio> #define MOD…
听说正解是啥 set启发式合并+维护凸包+二分 根本不会啊 , 只会 李超线段树合并 啦 ... 题意 给你一颗有 \(n\) 个点的树 , 每个节点有两个权值 \(a_i, b_i\) . 从 \(u\) 跳到 \(v\) 的代价是 \(a_u \times b_v\) . 你需要计算每个节点跳到叶子的最小代价 . \((n \le 10^5, -10^5 \le a_i, b_i \le 10^5)\) 题解 我们首先考虑一个很容易的 \(dp\) , 令 \(dp_i\) 为 \(i\)…