题意:一个棋盘上有一些"车",现在要让这些"车"跑到左倾斜的对角线上,每次可以移动一个棋子,但是棋盘的任意时刻都不能出现一个"车"能吃另一个"车"的情况.问最少需要移动多少次才能满足条件.("车"的个数小于对角线的格子数). 题解:对于某个棋子的位置\((x,y)\),我们可以\(x->y\)来建边,如果棋子已经在对角线上了,那么我们不用移动它们,也就不需要建边,否则一个棋子要么移动\(1\)次要么移…
A.In-game Chat 题目:就是从后面数连着的'('的个数是不是严格比剩下的字符多 思路:水题,直接从后往前遍历即可 代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> using namespace std; int main(){ char s[1500]; int t; scanf("%d…
考场上只做出来四道,第二天一早就写出来了E,蛮绝望的. A Finding Sasuke 水构造 #include <cstdio> #include <algorithm> typedef long long ll; int T,n; int a[110]; template <typename T> inline void read(T &x){ x = 0; char ch = getchar(); int f = 1; for(;ch < '0'…
题意:给你一组非递减的数,你可以对两个连续的数进行异或,使其合并为一个数,问最少操作多少次使得这组数不满足非递减. 题解:首先,给出的这组数是非递减的,我们考虑二进制,对于三个连续的非递减的最高位相同的数,我们可以将后面的两个异或,那么第一个数一定比合并的数大,所以当出现三个最高位相同的数时,操作数一定是\(1\),题目所给的\(a_i\)的最大值是\(1e9\),所以最多是\(2^{30}\),也就对应着\(30\)个最高位的情况,而当出现三个最高位相同的情况时操作数为\(1\),所以每个最高…
题意:有一长度为\(n\)的平台,平台有的位置有木桩,可以使小球弹起来,小球必须从第\(p\)个位置开始,而且每次都会向右弹\(k\)个单位,然后有的位置是没有木桩的,你可以在这些的空的位置放一个木桩,需要花费\(x\),在开始的时候,你可以删除前几个单位,每个单位花费\(y\),问最少花费多少使得小球能够弹出平台外. 题解:刚开始看错题意了,以为可以删除任意位置的单位,结果发现这个动态的过程根本没办法维护,又重新看了一眼题面发现只能删去相对第一个单位,然后这题就是一道sb题了,我们可以记录一个…
题意:有\(n\)栋房子,每栋房子都有自己的颜色\(c_i\),你每次可以对连续的长度为\(k\)的区间改变任何房子的颜色,问最少多少次可以使得所有房子颜色相同. 题解:因为只有\(100\)中颜色,所以我们可以直接枚举颜色,然后去遍历房子,如果房子颜色和当前枚举的不符,那么我们操作的次数就要++,并且跳到\(j+k+1\)栋房子继续. 代码: #include <bits/stdc++.h> #define ll long long #define fi first #define se s…
题意:有一张\(n\)x\(m\)的图,图中每个点都关押着罪犯,在坐标\((r,c)\)处有一个出口,每名罪犯每秒可以可以像上下最有移动一个单位或者不动,问所有罪犯能够逃离监狱的最少时间. 题解:直接算四个顶点到出口的值求个最大即可. 代码: #include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back #define me memset #define…
A. Prison Break 题意:就是在一个n*m的矩阵中,以(1,1)为起点(n,m)为终点,每个点以每个单位1s的速度移动,问总共至少需要多少秒,所有的矩阵点就能够全部移动到(r,c)中 思路:直接计算横坐标中最大需要多少秒,用最左边的点和最右边的点到r比较,纵坐标也是如此,然后算两者最大的加和 代码: 1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cmat…
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++.h> using namespace std; int n,m,k; ; int main() { cin>>n>>m>>k; ;i<=k-;++i) { sum+=(n+(m-))*-(i)*; } cout<<sum<<endl;…
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \(a=b\) 和 \(a=b-1\) 的时候有解,再加上一个从 \(9\) 越到 \(10\) 的就可以了.被样例的 \(199,200\) 误导了. #include<bits/stdc++.h> using namespace std; typedef long long ll; int mai…
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp loves ciphers. He has invented his own cipher called Right-Left. Right-Left cipher is used for strings. To encr…
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search…
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how…
A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros i…
http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/stdc++.h> using namespace std; #define ll long long #define minv 1e-6 #define inf 1e9 #define pi 3.1415926536 #define nl 2.7182818284 ; ; struct node {…
https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n,n]的路径(1<=n<=2000) 思路 我的 定义dp[i][j]为从[1,1]到[i,j]字符串最小的字符串,然后枚举所有i-1+j-1+1<=k的点,然后字符串连接比较,代表更改前面i,j个字符 这种思路有两个问题,如何处理出从[i,j]到[n,n]的最小字典序字符串,第二假如i+j…
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个数的数字即在A数组中出现过,也在B数组中出现过,问这个数最小是多少. 题目思路:首先要么一个数两个数组都出现过直接输出来,要么分别取两个数组中最小的数组合一下输出. 代码: //Author: xiaowuga #include <bits/stdc++.h> using namespace st…
地址:http://codeforces.com/contest/872/problem/D 题目: D. Something with XOR Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output This is an interactive problem. Jury has hidden a permutati…
A. k-rounding 题目意思:给两个数n和m,现在让你输出一个数ans,ans是n倍数且末尾要有m个0; 题目思路:我们知道一个数末尾0的个数和其质因数中2的数量和5的数量的最小值有关系,所以我们可以把n中的2和5的因子数量分别算出来,然后看一下是否都大于等于m,否则我们就把他们补成m个.然后再乘回去就结束了. 题目链接:http://codeforces.com/contest/861/problem/A 代码: /* *********************************…
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Squareland national forest is divided into equal 1×11×1 square plots al…
任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Recently Vasya found a golden ticket — a sequence which consists…
A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最长我们肯定是取最小x和最大的y连起来就完事. 但是要求长度最小又得覆盖,那么可以这样想,我们需要把最小的x不断右移到这条线段的y, 最大的左移到x,所以就是最大x-最小y完事 #include <bits/stdc++.h> using namespace std; #define ll long…
比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:…
链接: https://codeforces.com/contest/1247/problem/D 题意: You are given n positive integers a1,-,an, and an integer k≥2. Count the number of pairs i,j such that 1≤i<j≤n, and there exists an integer x such that ai⋅aj=xk. 思路: 对每个数质数拆分,记录质数的指数modk的值,map记录ve…
链接: https://codeforces.com/contest/1247/problem/C 题意: Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). T…
链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequen…
链接: https://codeforces.com/contest/1247/problem/A 题意: Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation a+1=b with positive integers a and b, but Kolya forgot the numbers a and b. He does, howev…
https://codeforces.com/contest/1241/problem/C You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something! You have n tickets to sell. The price of the i-th ticket is pi.…
题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问有多少个区间满足,区间内的数异或和为 0 . 题解:首先对于一个区间来说,区间内二进制为 1 的个数为奇数时显然不可能满足条件,先统计二进制为 1 的个数为偶数的区间总个数.而在一个区间内,如果某个数二进制下有 x 个 1 ,而区间内其他数的二进制 1 加起来小于 x ,则是不满足的,可以暴力去掉这…
链接: https://codeforces.com/contest/1241/problem/D 题意: You are given a sequence a1,a2,-,an, consisting of integers. You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning,…