D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially you are in th…
题目链接 题意:给你三个数n,k,sn,k,sn,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为sss, ∑i=1n∣a[i]−a[i−1]∣,a[0]=1\sum_{i=1}^n|a[i]-a[i-1]|,a[0]=1∑i=1n​∣a[i]−a[i−1]∣,a[0]=1. 思路:遍历每一步,找到当前能走的步数的最大可能,然后走就好了. 写这个博客是因为看cf的时候,有个远古题没补..好像是去年暑假的题了..今天翻出来补了一下,发现现在的思路明显比当时清晰,好像真的进步了一点…
题意:一共有\(n\)个房子,你需要访问\(k\)次,每次访问的距离是\(|x-y|\),每次都不能停留,问是否能使访问的总距离为\(s\),若能,输出\(YES\)和每次访问的房屋,反正输出\(NO\). 题解:最优解一定是让每次访问的距离为\(s/k\),然后将余数\(s\ mod\ k\)平均分配到前s%k的房屋中,之后每次访问\(s/k\)即可,也就是构造一个类似于\(x\ 1\ x\ 1\ x\ 1\)这样的一个序列,但因为有余数,所以要修改. 代码: #include <iostre…
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60949 ....看不懂 设dp[i][j][l]表示前i位,左括号-右括号=j,匹配到l了 状态转移,枚举下一个要填的括号,用next数组求状态的l,分别转移 代码 #include<bits/stdc++.h> using namespace std; const int maxn = 207;…
A - Points in Segments 题意:implement #include<bits/stdc++.h> using namespace std; typedef long long ll; bool vis[105]; int ans[105], atop; void test_case() { int n, m; scanf("%d%d", &n, &m); while(n--) { int u, v; scanf("%d%d&q…
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a set of nn segments on the axis OxOx , each segment has integer endpoints between 11 and mm inclusive. S…
A:https://www.cnblogs.com/myx12345/p/9842904.html B:https://www.cnblogs.com/myx12345/p/9842964.html C:https://www.cnblogs.com/myx12345/p/9842977.html D:https://www.cnblogs.com/myx12345/p/9852909.html E:https://www.cnblogs.com/myx12345/p/9932309.html…
题意:有两个字符串\(S\)和\(T\),判断\(T\)是否能由\(S\)通过交换某位置的相邻字符得到,如果满足,输出交换次数及每次交换的位置,否则输出\(-1\). 题解:首先判断不满足的情况,只有当两个字符串中出现的字母次数不同时不满足条件,用桶判断一下即可.然后我们再来看有解的情况,我们对\(T\)的每个字符标上序号,如样例1中:\(abdfec\)对应\(123456\),则\(S\)中与之对应的是\(abcdef\)->\(126354\),所以要想让\(S\)变成\(T\),就要让其…
Codeforces Round #552 (Div. 3) 题目链接 A. Restoring Three Numbers 给出 \(a+b\),\(b+c\),\(a+c\) 以及 \(a+b+c\) 这四个数,输出一种合法的 \(a,b,c\).   可以发现,前面的两个数加起来减去最后的 \(a+b+c\),答案就出来一个.最后这样求出\(a,b,c\)即可. 代码如下: Code #include <bits/stdc++.h> using namespace std; typede…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…