- 博客(16)
- 收藏
- 关注
原创 B. Two Arrays
传送门 题目 RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T. Let’s denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i,j) such that 1≤i<j≤m and bi+bj=T. RedDreamer has to pai
2020-11-12 21:41:22
218
原创 Codeforces——B. Longest Palindrome
Codeforces——B. Longest Palindrome 传送门 Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings “pop”, “noon”, “x”, and “kkkkkk” are palindro
2020-11-11 21:06:42
217
原创 codeforces Round #678 (Div. 2) 1436
A. Reorder 题解 就是求数组a里面元素的和 判断是否与 k 相等 #include<iostream> #include<algorithm> using namespace std; const int N = 1e6 + 10; int t, n, k, a; int main () { cin >> t; while(t -- ) { int res = 0; cin >> n >> k; for(int
2020-11-01 21:14:47
171
原创 Codeforce 1420.B
传送门 题目 Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them. Hermit Lizard agreed to give Danik the lever. But to get a stone, Danik needs to solve the following task. You are given a positive
2020-09-27 16:53:22
191
原创 Acwing 788 逆序对的数量归并排序
传送门 文章目录题目大意输入格式输出格式数据范围输入样例:输出样例:题解 题目大意 给定一个长度为n的整数数列,请你计算数列中的逆序对的数量。 逆序对的定义如下:对于数列的第 i 个和第 j 个元素,如果满足 i < j 且 a[i] > a[j],则其为一个逆序对;否则不是。 输入格式 第一行包含整数n,表示数列的长度。 第二行包含 n 个整数,表示整个数列。 输出格式 输出一个整数,表示逆序对的个数。 数据范围 1≤n≤100000 输入样例: 6 2 3 4 5 6 1 输出样例: 5
2020-09-19 18:55:17
172
原创 浮点数的二分 Acwing790 数的三次方根
浮点数的二分 传送门 题目大意 给定一个浮点数n,求它的三次方根。 输入格式 共一行,包含一个浮点数n。 输出格式 共一行,包含一个浮点数,表示问题的解。 注意,结果保留6位小数。 数据范围 −10000≤n≤10000−10000≤n≤10000 输入样例: 1000.00 输出样例: 10.000000 注意: 题目要求保留小数点后6位 题解 #include <iostream> using namespace std; const int esp = 1e-8; double n;
2020-09-19 11:05:48
178
原创 快速排序 快速选择排序 Acwing 786第k个数
s://www.acwing.com/problem/content/788/) 题目大意 基本上就是裸体 给定一个长度为n的整数数列,以及一个整数k,用快速选择算法求出数列的第k小的数是多少。 输入格式 第一行包含两个整数 n 和 k。 第二行包含 n 个整数(所有整数均在1~109109范围内),表示整数数列。 输出格式 输出一个整数,表示数列的第k小数。 数据范围 1≤n≤1000001≤n≤100000, 1≤k≤n 输入样例: 5 3 2 4 1 5 3 输出样例: 3 注意 在递归的时候一定要
2020-09-19 10:28:38
351
原创 整数二分 Acwing 789数的范围
整数二分 注意边界问题 为了避免死循环 传送门 l = mid 时 mid = l + r + 1 >> 1; //因为在c/c++ 里面是向下取整 同理 r = mid 时 mid = l + r >> 1; 下面直接给出了本题的题解 #include<iostream> using namespace std; const int N = 1e5 + 10; int n, q, k, a[N]; int main () { scanf("%d %d
2020-09-19 09:38:32
227
原创 快速排序 Acwing 785快速排序
快速排序 nlogn 模板题 #include <iostream> using namespace std; const int N = 1e5 + 10; int n; int a[N]; void quick_sort(int q[], int l, int r) { if(l >= r) return ; int x = q[(l + r) / 2], i = l - 1, j = r + 1; while(i < j) {
2020-09-18 14:07:22
124
原创 归并排序 Acwing 787
归并排序 nlongn 运用分治的思想 递归 #include<iostream> using namespace std; const int N = 1e5 + 10; int n; int a[N], temp[N]; void merge_sort(int q[],int l,int r) { if(l >= r) return ; int mid = l + r >> 1; merge_sort(q, l, mid); mer
2020-09-18 14:01:11
165
原创 POJ 3974 Palindrome manacher 马拉车
传送门 manacher算法: 定义数组p[i]表示以i为中心的(包含i这个字符)回文串半径长 id 表示回文子串的中心位置 mx 表示回文子串的最右边的位置 假设原字符串为”abcba“, 然后构造一个新的字符串“@#a#b#c#b#a#" (解决奇数偶数造成的分类) 题解 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algor
2020-07-13 16:41:19
139
原创 greater和less的用法
greater使内置函数从大到小排序,而less使的内置函数从小到大排序。 注意:sort 用greater排序,是a[0]到a[n]从大到小排序 priority_queue用greater排序,是先出最小值 #include #include<bits/stdc++.h> #include using namespace std; int main () { int a[10]={...
2019-11-14 13:32:49
1408
2
原创 二分法 Pie HDU - 1969
#include< cstdio> #include< cmath> #include< iostream> #include< algorithm> using namespace std; #define eps 1e-7 const double PI=acos(-1.0); //精确计算π的值,减小误差 int n,f; double ca...
2019-11-13 16:49:10
160
原创 字符串逆转
下面介绍了两种字符串逆转的方法 #include < iostream > #include<bits/stdc++.h> #include< algorithm> #include< string> using namespace std; #define N 20 #define M 30 int main () { int len; char...
2019-11-11 20:47:35
119
原创 逆转函数 的使用
逆转函数reverse的使用 #include iostream #include<bits/stdc++.h> #include algorithm using namespace std; int main () { int a[5]={1,2,3,4,5}; float b[5]={1.1,2.2,3.3,4.4,5.5}; reverse (a,a+5); reverse a...
2019-11-11 20:31:18
239
原创 sort排序
#include #include using namespace std; bool cmp(int a,int b) { return a>b; } int main () { int a[10]={56,23,1,2,4,3,5,7,8,65}; sort(a,a+10); int i; for(i=0;i<10;i++...
2019-11-10 10:27:51
107
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人