作业:2020_04_26

两部分
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(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值