Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Pattern Matching 题意就是匹配字符的题目,打比赛的时候没有看到只有一个" * ",然后就写挫了,被hack了,被hack的点就是判一下只有一个" * ". 代码: //A #include<iostream> #include<cstdio>…
B. Pair of Toys 智障题目(嘤嘤嘤~) 代码: 1 //B 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 #include<bitset> 7 #include<cassert> 8 #include<cctype> 9 #include<cmath> 10 #include&…
D. Array Restoration 这题想一下就会发现是只要两个相同的数之间没有比它小的就可以,就是保存一下数第一次出现和最后一次出现的位置,然后查询一下这个区间就可以,如果有0的话就进行填充. 这个题我是用RMQ(ST)进行查询的,在初始化的时候,如果有0就把0变成2e5+1,因为数据最大2e5,然后区间查询就可以了,关于RMQ(ST),以前写过博客,有兴趣的可以看一下 RMQ(ST)详解 这个题坑点很多,首先如果这个序列一开始的最大值比m小,并且没有0,那么就是NO,有0就先把一个0变…
C. Bracket Subsequence ... 代码: 1 //C 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 #include<bitset> 7 #include<cassert> 8 #include<cctype> 9 #include<cmath> 10 #include&…
http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义:从x走到y(即x->y)后,和x所连接的边的所有状态都反转(即开启->关闭,关闭->开启) 问,从起点1走到终点n,最少需要经过几步,并且输出这个路径(如果存在多挑最短路径,输出任意一条) 如果不存在,则输出-1 思路: 其实这道题第一眼看过去就是bfs,不过,由于每个状态都在改变,那要怎么…
http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <time.h> #include <string> #include <set> #include <map> #include <list&g…
http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x2. 运行任务的条件: ①每个服务器只能同时运行一个任务 ②任务可以同时分配到多个服务器中执行.假设任务x1分配到a个服务器中,则每个服务器都需要使用x1/a的资源(该资源可以为小数) 问能否满足以上条件,使得x1,x2同时在服务器中运行? 思路: 将所有服务器按照资源增序排列,定义dp(i)表示从…
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mat…
http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd(a[x-1],a[z])<>0 ) f[x][y][1]=f[x][z][1] & f[z+1][y][0] ( gcd(a[z],a[y+1])<>0 ) #include <cstdio> #include <cstdlib> #include &l…
http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问,是否存在一种情况,使得a(i)重新排列以后以后,满足b(i)是严格单调递增的. 思路: 对于二进制位操作来说,如果异或后值增加,即 p^q > p,必然满足两种情况(假定一个为p,一个为q) ①q的最高位>p的最高位 ②q的最高位(假定第k为最高) < p的最高位,但是p的第k位为0 这样,…