题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j-1],求f[n][n].C++代码: #include <iostream> using namespace std; ][]; int main() { cin >> n; ;i<=n;i++) f[i][] = f[][i] = ; ; i <= n; i ++) ;…
E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes m…
A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An n × n table a is defined as follows: The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for…
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量之差 <= 1. 如果不填充某种颜色,就默认数量为0. 1. 贪心:如果个数之间超过k个,那么填充什么颜色都会大于1,巧妙地思维 详细解释:http://blog.csdn.net/haoliang94/article/details/43672617 2. 比较每种填充颜色在n组里使用最多和最少的…
题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include <algorithm> #include <cstring> #include <string> #include <map> using namespace std; + ; const int INF = 0x3f3f3f3f; int a[MAXN][M…
Codeforces Round #116 (Div. 2, ACM-ICPC Rules) 代码 Codeforces Round #116 (Div. 2, ACM-ICPC Rules) A. Defragmentation 按颜色分配\(1\)到\(\sum_{i=1}^{m}{n_i}\)位置,那么可以得到\(t_i\)表示位置\(i\)最后占据位置\(t_i\),-1表示该位置为空. 那么会出现两种情况: \(t_1 \to t_2 \to \cdots \to \ {-1}\),即…
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n 和你两场分赛的排名 x, y,问你最终名次最小和最大可能是多少. 思路: 以8人为例: x + y = 2,最小第一名,最大第一名:               1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1               x + y = 3,最小第一名,最大第二名.…
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序列的长度是多少. 将相同颜色的下标存到对应颜色的容器中,比如ans[a[i]].push_back(i)就是将下标为i颜色为a[i]的数存到ans[a[i]]容器中. 对于每种颜色序列,尺取一下 在差距小于k的情况下取能取到的最大长度. //#pragma comment(linker, "/STA…
C. Letter Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/180/problem/C Description Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervou…
Letter time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was n…
题意 有nnn个点,每个点只能走到编号在[1,min(n+m,1)][1,min(n+m,1)][1,min(n+m,1)]范围内的点.求路径长度恰好为kkk的简单路径(一个点最多走一次)数. 1≤n≤109,1≤m≤4,1≤k≤min(n,12)1\le n\le 10^9,1\le m\le 4,1\le k\le min(n,12)1≤n≤109,1≤m≤4,1≤k≤min(n,12) 分析 直接考虑走路径的话不能判有没有走过,然后就把路径转化为一个序列,每次往里面插入新的点(神了).因为…
题目链接:http://codeforces.com/contest/785 A. Anton and Polyhedrons time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anton's favourite geometric figures are regular polyhedrons. Note that there…
B - Hongcow Solves A Puzzle 题目连接: http://codeforces.com/contest/745/problem/B Description Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be…
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一个满足条件的四个点. 题解: 首先预处理出任意两点的最短距离,用队列优化的spfa跑:O(n*n*logn) 现依次访问四个点:v1,v2,v3,v4 我们可以枚举v2,v3,然后求出v2的最远点v1,v3的最远点v4,为了保证这四个点的不同,直接用最远点会错,v1,v4相同时还要考虑次最远点来替换…
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains…
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami is an expert at playing games. This day, Nanami's good friend Hajime invited her to watch a game of baseball. Unwilling as she was, she followed him to…
D. Vanya and Treasure 题目连接: http://www.codeforces.com/contest/677/problem/D Description Vanya is in the palace that can be represented as a grid n × m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains t…
D. DZY Loves Strings 题目连接: http://codeforces.com/contest/444/problem/D Description DZY loves strings, and he enjoys collecting them. In China, many people like to use strings containing their names' initials, for example: xyz, jcvb, dzy, dyh. Once DZ…
B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem/B Description The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per…
http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字符,密码至少包含3种字符:数字,小写字母,特殊符号)的情况下使得移动的光标步数最小. 思路: 因为每个串只提供一个密码,所以我们先预处理计算出每个字符串3种字符的最少移动步数. 然后接下三重循环枚举,分别表示数字,小写字母,特殊符号由第i,j,k行提供. #include<iostream> #i…
http://codeforces.com/contest/761/problem/B 题意: 有一个长度为l的环形跑道,跑道上有n个障碍,现在有2个人,给出他们每过多少米碰到障碍,判断他们跑的是不是同一个跑道. 思路: 如果是同一个跑道,那么障碍与障碍之间的距离是相同的. 所以我们可以先计算出两个人的跑道的障碍之间的距离,然后暴力比较,如果全部一样就是同一个跑道(因为是环形跑道,所以在比较的时候每次都需要将第一个加到最后). #include<iostream> #include<st…
B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of…
题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各种bug不对. 这次用了一下优先队列,以前用的不多,看这个博客又学了一下 AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <…
称号: 意甲冠军:给定一个矩阵,每格我们有一个数,然后把两个大象,我希望能够吃的对角线上的所有数字.我问两个最大的大象可以吃值. 分析:这种想法是暴力的主题,计算出每一格放象的话能得到多少钱,然后求出两个不冲突的最大值.我比赛的时候写的方法是先求出每个值,编号之后存到数组里面,然后在通过一系列处理得到,总之非常麻烦.写了一个多小时.最后才发现有一点小错误,没时间了.初始例子也没有通过. 然后看了下别人写的,太简洁了.直接用行和列和和差就能够直接求出来.看来代码能力还很有待提高啊. 我的AC代码:…
A. Salem and Sticks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Salem gave you nn sticks with integer positive lengths a1,a2,…,ana1,a2,…,an. For every stick, you can change its length t…
A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citi…
由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出.这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷...是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一步一步的优化,不能盲目的想. 这道题要AC的快需要熟悉string的各种用法.这里做个简单总结:C++中string的常见用法. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstrin…
A. Buy a Shovel time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is so…
A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When…