zl程序教程

codeforces 676C

  • Codeforces 414B

    Codeforces 414B

    大家好,又见面了,我是你们的朋友全栈君。题目链接附上代码:#include <cstdio> #include <cstring> #include <bits/stdc++.h> #define mod 1000000007 int n, k; // dp[len][last] int dp[2005][2005]; int main(void) {

    日期 2023-06-12 10:48:40     
  • Educational Codeforces Round 132 (Rated for Div. 2) A·B·C

    Educational Codeforces Round 132 (Rated for Div. 2) A·B·C

    A. Three Doors原题链接Origional Link思想从拿到钥匙的门开始,用其得到的钥匙遍历对应的门直到钥匙为0,若共打开了3道门,则为YES代码#include <bits/stdc++.h> using namespace std; const int N = 10; void solve(){ int a[N]; int n; ci

    日期 2023-06-12 10:48:40     
  • Codeforces Round #805 (Div. 3)(A~C)

    Codeforces Round #805 (Div. 3)(A~C)

    A. Round Down the Price题目大意Origional Link对于一个数N,求其最接近且不大于该数的10^m输出N-10^m思想初始化p = 1e10,循环枚举p = p / 10直到p < n代码#include <bits/stdc++.h> using namespace std; typedef long long LL; void solve()

    日期 2023-06-12 10:48:40     
  • Codeforces Round #826 (Div. 3)(A~D)

    Codeforces Round #826 (Div. 3)(A~D)

    A. Compare T-Shirt SizesOrigional Link题目大意:给定不同衬衫大小的尺寸编号如:S,M,L。除 M 之外,X 作为尺寸前缀代表其倍数大小。如:XXL\gt XL,XXS\lt XS。给定两个代表衬衫尺寸的字符串,判断衬衫大小。思想:签到题。判断模拟即可。代码:#include <iostream> #include <cstring> #

    日期 2023-06-12 10:48:40     
  • Codeforces Round #825 (Div. 2) (A~C1)

    Codeforces Round #825 (Div. 2) (A~C1)

    A. Make A Equal to BOrigional Link题目大意:给定只含 0,1 的序列 a,b。对序列 a 不限次数执行如下操作: 将 a_i 变为 a_i - 1 。 将 a 按照任意顺序重新排列。 求最少几步可以得到和 b 相同的序列 a。思想: 思维题。分为两种情况讨论:不排序 a 直接操作和先排序 a 再操作的情况。 同时遍历一遍 a 和 b,记录 a[i] != b[

    日期 2023-06-12 10:48:40     
  • Codeforces Round #674 (Div. 3)(A~D)

    Codeforces Round #674 (Div. 3)(A~D)

    A. Floor NumberOrigional Link题目大意:给定目标房间编号 n 及一层楼住户数量 x。第一层楼只有 2 个住户,求目标房间所在楼层。思想:签到题。n\le2 时在第一层。n\gt 2 时: 若 x 可以整除 n-2,则在 \frac{n-2}{m} + 1 层; 反之在 \frac{n-2}{m} + 2 层。 代码:#include <iostream>

    日期 2023-06-12 10:48:40     
  • CodeForces – 1312D 组合数

    CodeForces – 1312D 组合数

    这题主要就是涉及到满足条件的组合数,思路:从m个数中选择n-1个不同的数。由于里面的元素只有一个重复,而且重复的元素不能是最大值,那么就要从剩下的n-2个数中选择出一个最大值,下标为i。对于剩下的n-3个数,选x个排在最大值的左侧,这样的话,总共的情况数就是C(n-1,m)*(n-2)*(2^(n-3))那么代码就很简单了。但是问题来了,这个组合数会很大,要模除一个数。然后由于同余线性方程组没有除

    日期 2023-06-12 10:48:40     
  • Codeforces Global Round 23(A~C)

    Codeforces Global Round 23(A~C)

    A. MaxminaOrigional Link题目大意:给定长度为 n 只包含 0,1 的序列 a,和一个整数 k,保证 (2\le k\le n\le 50)。不限次数进行如下操作: 将连续且相邻的两个元素变为较小的一个。 将连续的 k 个区间的元素变为区间内元素最大的哪一个。 求给出的序列是否可以变为只包含 1 的序列。思想:签到题。保证 (2\le k\le n\le 50) 即保证了

    日期 2023-06-12 10:48:40     
  • Codeforces Round #828 (Div. 3) (A~D)

    Codeforces Round #828 (Div. 3) (A~D)

    A. Number ReplacementOrigional Link题目大意给定一个序列 a 和一个字符串 s。可以将相同的 a_i 替换为 s_i,若a_i 对应的替换规则唯一。求是否可以在满足上述条件下完成替换。思想:思维。当 s_i 所对应的 a_i 首次出现时建立对应规则。若 s_i 对应的 a_i 出现过且规则不同说明无法完成替换。代码:#include <iostream>

    日期 2023-06-12 10:48:40     
  • Codeforces 456 A. Laptops「建议收藏」

    Codeforces 456 A. Laptops「建议收藏」

    大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。 Jetbrains全系列IDE稳定放心使用 题目链接:http://codeforces.com/contest/456/problem/A 提示:一共有n个数,而且a[i],

    日期 2023-06-12 10:48:40     
  • C. Polycarp Restores PermutationCodeforces Round #547 (Div. 3)

    C. Polycarp Restores PermutationCodeforces Round #547 (Div. 3)

    Codeforces Round #547 (Div. 3)复制 #include <bits/stdc++.h> #define ll long long using namespace std; int n,m; map<int,int> mp; ll pre[200005],s[200005],a[200005]; int main() { scanf(&qu

    日期 2023-06-12 10:48:40     
  • CodeForces 750A New Year and Hurry

    CodeForces 750A New Year and Hurry

    #include<bits/stdc++.h> using namespace std; int main() { int n, k, i, sum; while(~scanf("%d%d",&n, &k)) { sum = k; for(i = 0; i <= n; i ++)

    日期 2023-06-12 10:48:40     
  • CodeForces - 999C  Alphabetic Removals

    CodeForces - 999C Alphabetic Removals

    C - Alphabetic RemovalsYou are given a string   consisting of   lowercase Latin letters. Polycarp wants to remove exactly   characters ( ) from the string  . Polycarp uses the following algorithm   t

    日期 2023-06-12 10:48:40     
  • CodeForces - 999B  Reversing Encryption

    CodeForces - 999B Reversing Encryption

    B - Reversing EncryptionA string  of length  can be encrypted by the following algorithm:iterate over all divisors of  in decreasing order (i.e. from  to ),for each divisor , reverse the substring  (i

    日期 2023-06-12 10:48:40     
  • A. Vasya and Book ( Codeforces   Educational Codeforces Round 55 )

    A. Vasya and Book ( Codeforces Educational Codeforces Round 55 )

    题意:当前在看书的第 x 页,每次可以向前或者向后翻 d 页,这个书一共 n 页,问能否用最小操作翻到第 y 页。 题解:三种情况:1、直接翻能到的一定最短。 2、先翻到第一页,然后往后翻,翻到第 y 页。3、先翻到第 n 页,然后往前翻,翻到第 y 页。#include<bits/stdc++.h> using namespace std; typedef long long l

    日期 2023-06-12 10:48:40     
  • C. Prefixes and Suffixes ( Codeforces Round #527 (Div. 3) )

    C. Prefixes and Suffixes ( Codeforces Round #527 (Div. 3) )

    题意:给你一个 n 长度的字符串,给你 2n - 2 个子串,其中有 n - 1 个前缀和 n - 1 个后缀,输出一个合法的判断。题解: 找到 n - 1 长的子串一个是(假设第一个是)最长前缀,另一个是最长后缀。 判断假设是否正确,遍历所有子串,如果符合前缀 tot 加 1,如果 tot 不够 n - 1 或者我们假设的那个前缀从第二个开始不等于那个后缀的前 n - 2 个,也就是我们假设

    日期 2023-06-12 10:48:40     
  • CodeForces 91A Newspaper Headline

    CodeForces 91A Newspaper Headline

    题目描述 A newspaper is published in Walrusland. Its heading is s 1 , it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue

    日期 2023-06-12 10:48:40     
  • codeforces D. Design Tutorial: Inverse the Problem

    codeforces D. Design Tutorial: Inverse the Problem

    题意:给定一个矩阵,表示每两个节点之间的权值距离,问是否可以对应生成一棵树,使得这棵树中的任意两点之间的距离和矩阵中的对应两点的距离相等!思路:我们将给定的矩阵看成是一个图,a 到 b会有多条路径, 如果存在一棵树,那么这个树中a- b的距离一定是这个图中所有a- b中路径长度最短的一条!所以我们根据边权,建立一棵MST树!再将MST树中的任意两点之间的距离求出来,看是否和矩阵中的对应的节点对距离

    日期 2023-06-12 10:48:40     
  • codeforces B. Design Tutorial: Learn from Life

    codeforces B. Design Tutorial: Learn from Life

    题意:有一个电梯,每一个人都想乘电梯到达自己想要到达的楼层!从a层到b层的时间是|a-b|, 乘客上下电梯的时间忽略不计!问最少需要多少的时间....     这是一道神题啊,自己的思路不知不觉的就按照注解的思路走了,想着用优先队列模拟一下,可能还是没有模拟好吧,一直哇!但是同学的优先队列模拟过了! 没想到是greedy算法简单的几行就解决了! #include iostream #i

    日期 2023-06-12 10:48:40     
  • codeforces Restore Cube(暴力枚举)

    codeforces Restore Cube(暴力枚举)

    /* 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 问是否可以还原出一个立方体的坐标,注意这一句话: The numbers in the i-th output line must be a permutation of the numbers in i-th input line! 我们只要对输入的每一行数据进行枚举每一个排列, 然后检查时

    日期 2023-06-12 10:48:40     
  • codeforces B. Strongly Connected City(dfs水过)

    codeforces B. Strongly Connected City(dfs水过)

    题意:有横向和纵向的街道,每个街道只有一个方向,垂直的街道相交会产生一个节点,这样每个节点都有两个方向,问是否每一个节点都可以由其他的节点到达....思路:规律没有想到,直接爆搜!每一个节点dfs一次,记录每个节节点被访问的次数!如果每个节点最终的访问次数和所有节点的数目相同,则输出“YES", 否则输出”NO“ #include queue #include string #inc

    日期 2023-06-12 10:48:40     
  • codeforces A. Bayan Bus(简单模拟)

    codeforces A. Bayan Bus(简单模拟)

    [HDU 7136] Jumping Monkey | 并查集 | 逆向思维 Jumping Monkey Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 747 Accepted Submission(s): 360

    日期 2023-06-12 10:48:40     
  • codeforces C. Bits(数学题+或运算)

    codeforces C. Bits(数学题+或运算)

    题意:给定一个区间,求区间中的一个数,这个数表示成二进制的时候,数字1的个数最多!如果有多个这样的数字,输出最小的那个!思路:对左区间的这个数lx的二进制 从右往左将0变成1,直到lx的值大于右区间的值rx! #include iostream #include cstring #include cstdio #include algorithm using namespac

    日期 2023-06-12 10:48:40     
  • codeforces B. Ohana Cleans Up

    codeforces B. Ohana Cleans Up

    Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her b

    日期 2023-06-12 10:48:40     
  • codeforces C. Vanya and Scales

    codeforces C. Vanya and Scales

    Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2(exactly one weight of each nominal value). Vanya wonders whether he can

    日期 2023-06-12 10:48:40     
  • 【Educational Codeforces Round 101 (Rated for Div. 2) C】Building a Fence

    【Educational Codeforces Round 101 (Rated for Div. 2) C】Building a Fence

    题目链接 链接 翻译 让你放长度为 \(k\) 的长条,相邻两列必须有一个公共位置,路不是平的,长条必须放在某个高度之上。 且最高不能高过路高上面 \(k-1\)。 规定第一列和最后一列只能老老实实放在路面上。 问你能否符合上述要求放好所有的长条。 题解 每一列处理出来一个可能的长条占据的区域 \(Occpied\) 的上下界,然后以此来决定下一列可以放长条的上下界。 根据这个上下界,和第 \(

    日期 2023-06-12 10:48:40     
  • 【Codeforces Round #696 (Div. 2) C】Array Destruction

    【Codeforces Round #696 (Div. 2) C】Array Destruction

    题目链接 链接 翻译 让你一开始的时候选定一个 \(x\) 的值,然后从数组中找到两个数 \(a[i]\) 和 \(a[j]\),使得他们的和为 \(x\),然后从数组中移除掉这两个数字 \(a[i]\) 和 \(a[j]\)。 然后用 \(a[i]\) 和 \(a[j]\) 中的较大者代替 \(x\),重复上述移除过程,直到数组为空。 回答能否找到这样的 \(x\)。如果能找到,输出每次选择的

    日期 2023-06-12 10:48:40     
  • 1800*2【Codeforces Round #612 (Div. 1) A】Garland

    1800*2【Codeforces Round #612 (Div. 1) A】Garland

    题目链接 链接 翻译 给你一个排列,其中有一些位置上的数字被remove了,让你全都放回去。 定义相邻两个数字如果奇偶性不同,\(diff\) 值加 \(1\)。 求数字全都放回去之后 \(diff\) 的值的最小值。 题解 设 \(dp[i][j][k]\) 表示前 \(i\) 个数字放了 \(j\) 个偶数,最后一个数字奇偶性为 \(k\) 的最小 \(diff\)。 之所以可以只用偶数的个

    日期 2023-06-12 10:48:40     
  • 1800*1【Codeforces Round #665 (Div. 2) D】Maximum Distributed Tree

    1800*1【Codeforces Round #665 (Div. 2) D】Maximum Distributed Tree

    题目链接 链接 翻译 让你给树上的每条边分配一个数字。要求这 \(n-1\) 个数的乘积要等于 \(k\) 分配的 \(1\) 的个数要尽可能少。 这个 \(k\) 质因数分解的时候,每个质因子的指数都是 \(1\),且 \(k\) 是以告诉你它每个质因子的形式给出的。 要求树上任意两点之间的距离和最大。输出这个最大值。 题解 感觉证明做法的正确性会比做法本身难。。 首先解决两点之间距离和这个问

    日期 2023-06-12 10:48:40     
  • 【Codeforces Round #650 (Div. 3) D】Task On The Board

    【Codeforces Round #650 (Div. 3) D】Task On The Board

    题目链接 链接 翻译 将 \(s\) 删掉 \(|s|-m\) 个字符之后,剩下的 \(m\) 个字符任意排序得到 \(t\)。根据 \(t\) 上每个字符的字典序的大小关系生成了一个序列 \(b\)。 现在告诉你 \(s\) 以及 \(m\) 和 \(b\) 让你输出某个可能的 \(t\)。 题解 \(trick\) 就是每次找到 \(b\) 的值为 \(0\) 的位置,其他不为 \(0\)

    日期 2023-06-12 10:48:40     
  • 【Codeforces Round #643 (Div. 2) C】Count Triangles

    【Codeforces Round #643 (Div. 2) C】Count Triangles

    题目链接 链接 翻译 让你找 \(3\) 条边 \(x,y,z\), 要求 \(A\le x\le B\le y\le C\le z\le D\) 且 \(x,y,z\) 能组成三角形。 问你这样的 \(x,y,z\) 的个数。 题解 对于最后选出来的边,我们只需要关注 \(x+y\) 是不是大于 \(z\) 就好了 (两边之和大于第三边)。 因为 \(x<=y<=z\) 且 \(x

    日期 2023-06-12 10:48:40