两部分
1、二分
2、总结cf
1、二分算法
bool bFind(int a[], int left, int right, int tag)
{
for (; left <= right; ) {
int mid = (left + right) >> 1;
if (a[mid] == tag)
return true;
else
a[mid] < tag ? l = mid + 1 : r = mid - 1;
}
return false;
}
个人感觉,二分算法就是挨个试的升级版
前提必须是有顺序,否则怎么试也白搭
没有顺序的话就千万别考虑二分算法
在有顺序的前提下,试的数小了,就放大;试的大了,就缩小
有点像小时候玩的那种猜数游戏
不过算法这个东西,经常是看起来简单,用起来博大精深
想起了新生赛那个题目。隐隐约约感觉只能一个一个试(二分?),但是感觉那个数量级太大了;当时感觉够呛能解决那么大数据范围。好不容易瞎猫撞上死耗子,猜对了,却写的死循环。还有,以后要注意double的比较精度问题。
不得不说,这个指数级下降时间复杂度,太神奇了
还有那个e,真神奇。等情绪好点后要好好学学高等数学
数学是自然科学的基础啊。算法应该算是数学的内容之一吧。
可惜,depression这么多年,没有以前那种学习的兴奋了。虽然没啥情绪波动可以保护自己,但是太没活力了。
没事,慢慢来吧。当出来种地学校就是为了游泳池。来了学校,感觉比以前学校好,虽然排名比17年翻了一倍……当初就不应该乱报志愿
不过自己这状态,唉。更可怕的是这几天还经常梦到复读。这几年,唉……罢了,走一步看一步吧。希望大三考研前能好一点。等有了游泳池,多运动。
补一下算法的时间复杂度优化数据
2、总结下cf
不得不说,这个挺好玩的,可惜在深夜。
等起来挺想睡觉,但是一但等到,两个小时意犹未尽,过的挺快
本周打了两场:
div3 ac1-3
div2 ac1(第二题感觉没问题,结果只接受了test 1,迷)
补一下题(还要补作业,就只补补没做出来的那下一个题吧,毕竟已经读完题了)
另外,吐槽下谷歌机翻,太烂,没啥卵用
Codeforces Round #636 (Div. 3) D
You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All ai does not exceed some integer k.
Your task is to replace the minimum number of elements (replacement is the following operation: choose some index i from 1 to n and replace ai with some integer in range [1;k]) to satisfy the following conditions:
after all replacements, all ai are positive integers not greater than k;
for all i from 1 to n2 the following equation is true: ai+an−i+1=x, where x should be the same for all n2 pairs of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.
The first line of the test case contains two integers n and k (2≤n≤2⋅105,1≤k≤2⋅105) — the length of a and the maximum possible value of some ai correspondingly. It is guratanteed that n is even (i.e. divisible by 2). The second line of the test case contains n integers a1,a2,…,an (1≤ai≤k), where ai is the i-th element of a.
It is guaranteed that the sum of n (as well as the sum of k) over all test cases does not exceed 2⋅105 (∑n≤2⋅105, ∑k≤2⋅105).
Output
For each test case, print the answer — the minimum number of elements you have to replace in a to satisfy the conditions from the problem statement.
Example
inputCopy
4
4 2
1 2 1 2
4 3
1 2 2 1
8 7
6 1 1 7 6 3 4 6
6 6
5 2 6 1 3 4
outputCopy
0
1
4
2
错误解:暴力搜索(wa)
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <vector>
using namespace std;
int a[200001];
int main(