Description Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length eq…
题意:给定一个字符,让你用前 k 个字符把它排成 n 长度,相邻的字符不能相等,并且把字典序最小. 析:其实很简单么,我们只要多循环ab,就行,最后再把剩下的放上,要注意k为1的时候. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 10000 + 5; const int INF = 0x3f3f3f3f; const int dr[] = {0, 0, 1,…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the followi…
You are given n strings ti. Each string has cost ci. Let's define the function of string , where ps, i is the number of occurrences of s in ti, |s| is the length of the string s. Find the maximal value of function f(s) over all strings. Note that the…
题目链接:http://codeforces.com/problemset/problem/289/B 题目意思:给出一个 n 行 m 列的矩阵和数值 d .通过对矩阵里面的数进行 + d 或者 - d 的操作,是否可以使矩阵上的所有数相等.可以的话输出最少的操作步数,否则输出 -1. 由于矩阵的排列对处理没什么影响,因此不需要用到二维数组存储.接着把矩阵中所有的数从小到大进行排序,要想算出最少的步数,很容易想到应该最中间的数(中位数)靠拢.最关键的是如何判断不能通过对矩阵中的数进行处理使得所有…
题目传送门 似乎我的解法和官方题解不太一样 纪念自己独立做出来的一道难度 2800 的题. 我们记 \(ans(x)\) 为 \([444...44,x]\) 的答案,显然答案为 \(ans(r)-ans(l)\) 其次我们考虑 \(a_i\) 与 \(a_{i+1}\) 之间有什么联系. 不难发现从 \(a_i\) 变到 \(a_{i+1}\),也就是把 \(a_i\) 末尾一系列 \(7\) 改为 \(4\),再把从右往左数第一个 \(4\) 改为 \(7\). 这样我们就可以枚举末尾 \(…
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output Given a string sss of length nnn and integer k (1≤k≤n)k\ (1≤k≤n)k (1≤k≤n). The string sss has a level xxx, if xxx is largest non-negative…
题意:给一个数 n,让你求一个排列,使得这个排列与0-n的对应数的异或之最大. 析:既然是异或就得考虑异或的用法,然后想怎么才是最大呢,如果两个数二进制数正好互补,不就最大了么,比如,一个数是100,那么我们只要找11,(都是二进制) 这不就正好么,一试,果然是这样.就是这样找,而且两两正好配对,如果多了一个就是0呗,也就是0.那知道一个数,怎么找那另一个和它互补的呢?其实很简单, 就是用111-100=11,就是利用这个,就能很轻松把这个题解决,注意可能超int,要用long long. 代码…
题意:给定 n 和k,n 表示有n个房子,然后每个有一个编号,一只鹅要从一个房间中开始走,下一站就是房间的编号,现在要你求出有多少种方法编号并满足下面的要求: 1.如果从1-k房间开始走,一定能直到 1. 2.如果从k+1到n 开始走,一定走不到 1. 3.如果从 1 开始走,那么一定能回到1,并且走过房间数不为0. 析:这个题,当时想了好久,其实并不难,当时是暴力过的,一看 k 最大才是8,那么应该不会TLE,然后就暴力了.首先这前 k 个数和后面的数,完全没有关系, 后面就是 n-k的 n-…
题意:给定 n * m 个数,然后每次只能把其中一个数减少d, 问你能不能最后所有的数相等. 析:很简单么,首先这个矩阵没什么用,用一维的存,然后找那个中位数即可,如果所有的数减去中位数,都能整除d,那就是可以,并且记录数据. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 500 + 5; const int INF = 0x3f3f3f3f; const i…