You are given three integers a≤b≤ca≤b≤c . In one move, you can add +1+1 or −1−1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this ope…
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和m个元素的数组p,p中元素表示可调换(p=[3,2]表示a中下标为3和下标为3+1的元素可调换,2和2+1可调换),问能否使得原数组成为非降序数组 思路:暴力,模仿冒泡排序 AC代码: #include<bits/stdc++.h> typedef long long ll; using name…
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ss consisting of nn lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in ss . I.e. if s=s= "abca&…
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有优势一点 不多废话  http://codeforces.com/contest/1311/problem/F 题目链接 题意是 给你一堆点的位置和他们运动的速度(可正可负),然后时间无限往后推的情况下问你他们之间所有点的最小距离之和.(不明白自行读题) n的范围是2,200000: 显然单纯的一个…
output standard output You are given an array aa of length nn . You are also given a set of distinct positions p1,p2,…,pmp1,p2,…,pm , where 1≤pi<n1≤pi<n . The position pipi means that you can swap elements a[pi]a[pi] and a[pi+1]a[pi+1] . You can app…
You are given two positive integers aa and bb . In one move, you can change aa in the following way: Choose any positive odd integer xx (x>0x>0 ) and replace aa with a+xa+x ; choose any positive even integer yy (y>0y>0 ) and replace aa with a−…
A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algorithm> using namespace std; int main(){ int kk; scanf("%d",&kk); while(kk--){ int n,m; cin>>n>>m; if(n==m) {printf("0\n&qu…
题意:给定节点数n和所有节点的深度总和d,问能否构造出这样的二叉树.能,则输出“YES”,并且输出n-1个节点的父节点(节点1为根节点). 题解:n个节点构成的二叉树中,完全(满)二叉树的深度总和最小,单链树(左/右偏数)的深度总和最大.若d在这个范围内,则一定能构造出来:否则一定构造不出来. 1.初始构造一颗单链树,依次把底部的节点放入上面的层,直到满足深度总和为d 2.若当前深度总和sum > d,则先拿掉底端节点. 拿掉后,若sum依然比d大,就直接把底端节点放入有空位的最上层: 拿掉后s…
题意:给定n个点的初始坐标x和速度v(保证n个点的初始坐标互不相同), d(i,j)是第i个和第j个点之间任意某个时刻的最小距离,求出n个点中任意一对点的d(i,j)的总和. 题解:可以理解,两个点中初始坐标较小的点的速度更大时,总有一个时刻后面的点会追上前面的点,d(i,j) =0. 否则,即后面的点的速度 <= 前面的点的速度时,两点之间的距离只会越来越大,d(i,j) = abs(xi - xj) (初始距离). 可以用直线来辅助理解:x = xi + v*t,横轴为t,纵轴为x,若两直线…
A.题意:通过加奇数减偶数的操作从a到b最少需要几步 签到题 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <queue> #include <deque> #include <map> using na…