【前言】咦?如今怎么流行打CF了?于是当一帮大爷在执着的打div 1的时候,我偷偷的在刷div 2。至于怎么决定场次嘛。一般我报一个数字A,随便再拉一个人选一个数字B。然后開始做第A^B场。假设认为机密性不高,来点取模吧。
然后今天做的这场少有的AK了。(事实上模拟赛仅仅做完了4题。最后1题来不及打了)
等等。话说前面几题不用写题解了?算了,让我难得风光一下啦。
【A】
好像是给定N个段和数K,你能够把某一段的L减一,把某一段的R加一,都算一次操作。终于要使得总长度%K=0。求最少操作次数。
直接贴代码算了。
#include<cstdio> using namespace std; int n,k,i,ans,x,y; int main() { scanf("%d%d",&n,&k); for (i=1;i<=n;i++) scanf("%d%d",&x,&y),ans+=y-x+1; if (ans%k==0) puts("0"); else printf("%d",k-ans%k); return 0; }
【B】
Little penguin Polo has an n × m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of row i and column j as aij.
In one move the penguin can add or subtract number d from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
The first line contains three integers n, m and d (1 ≤ n, m ≤ 100, 1 ≤ d ≤ 104) — the matrix sizes and the d parameter. Next n lines contain the matrix: the j-th integer in the i-th row is the matrix element aij (1 ≤ aij ≤ 104).
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
2 2 2 2 4 6 8
4
1 2 7 6 7
-1
题意是给出N*M个带权方格,每次操作仅仅能对每一个格子+或-d。
求把全部方块变成同样的权值最小操作次数,无解输出-1。判是否有解解非常easy,仅仅要权值A%d是否是定值,或者ΔA%d是否=0。
假设有解的话一定是改成中位数。
#include<cstdio> #include<algorithm> using namespace std; int a[100005],num,n,m,d,i,j,tot,ans; int main() { scanf("%d%d%d",&n,&m,&d); scanf("%d",&a[tot=1]);num=a[1]%d; for (i=1;i<=n;i++) for (j=1;j<=m;j++) { if (i==1&&j==1) continue; scanf("%d",&a[++tot]); if (a[tot]%d!=num) {puts("-1");return 0;} } sort(a+1,a+tot+1); for (i=1;i<=tot;i++) ans+=abs(a[i]-a[(tot+1)>>1])/d; printf("%d",ans); return 0; }
【C】
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 equals n), exactly k of these letters are distinct.
- No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds,si ≠ si + 1(1 ≤ i < n).
- Among all strings that meet points 1 and 2, the required string is lexicographically smallest.
Help him find such string or state that such string doesn't exist.
String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes.
A single line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters.
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
7 4
ababacd
4 7
-1
构造题。
构造一个字典序最小的小写字符串。使得相邻两个字母不同。并且恰好仅仅按顺序出现了K个字母。大概的想法就是前面一直a和b交替,后来K-2位一直沿着c,d。e放下去。
注意这道题是有