3.18实验+蓝桥杯+vue

文章讨论了编程实验中遇到的问题,涉及算法如MI估计器、蓝桥杯中的跳石头问题、N皇后(使用DFS)、字符串操作、数组结束位置查找,以及Vue中的数据监视机制,包括ref、watch和深度监视。最后提到了路由部分还未完成。
摘要由CSDN通过智能技术生成

实验

结果依旧不好,有点乱了,重新在一个文件夹里做了
重新跑源码,对比论文里的结果看看先
感觉MI估计器有点问题好像

蓝桥杯

跳石头(最小值最大化)

#include<iostream>
#include<cstdio>

using namespace std;

const int N = 50010;
int L, m, n;
int a[N];

bool check(int x)
{
	int t = n;
	int dis = 0; 
	for (int i = 1; i <= m + 1; i ++)
	{
		dis += (a[i] - a[i-1]);
		if (dis < x) t --;
		else dis = 0;
		if (t < 0) return false;

	}
	return true;
}
int main()
{
	cin >> L >> m >> n;
	for (int i = 1; i <= m; i ++) cin >> a[i];
	a[m + 1] = L;
	
	int l = a[1], r = L;
	for (int i = 1; i <= m+1; i ++) 
		l = min(l, a[i] - a[i-1]);
	while (l < r)
	{
		int mid = (l + r + 1) >> 1;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	
	printf("%d",l);
	return 0;
}

N皇后(DFS)

#include<iostream>
#include<cstdio>

using namespace std;

const int N = 11;
int n;
int l[N*2], r[N*2];
int row[N];

int res = 0;
void dfs(int x)
{
	if (x == 0)
	{
		res ++;
		return;
	}
	for (int i = 1; i <= n; i ++)
	{
		if (!row[i] && !l[x+i] && !r[x-i+n])
		{
			row[i] = l[x+i] = r[x-i+n] = 1;
			dfs(x-1);
			row[i] = l[x+i] = r[x-i+n] = 0;
		}
	}
	return;
} 
int main()
{
	cin >> n;
	dfs(n);
	printf("%d", res);
	return 0;
}

字符串

如果直接sizeof(a),这个的长度是a[10]的长度
可以用’\0’,找到字符串数组的结束位置

#include <iostream>
#include<cstring>

using namespace std;
int main()
{
  // 请在此输入您的代码
  char a[10];
  cin.get(a, 10);

  int res= 0;
  for (int i = 0; a[i] != '\0';i ++)
  {
  	if (a[i] != ' ')  	
  		res ++;
  }
  cout << res;
  return 0;
}

string 可以直接用==进行判断

string a,b,c;
cin >> a;

if (a == "IN")
{
    cin >> b >> c;
    if (c == "N")
        n.push(b);
    else v.push(b);

拼数

字符排序
给了几个数,要求首尾连接使最终的数最大
一开始用了优先队列,但是错的
比如 3,30,如果用优先队列,那么30>3,最后就是303
但是实际330才是最大的

#include<iostream>
#include<algorithm>
using namespace std;
int n;
string str[25];

bool cmp(string a, string b)
{
	return a+b > b + a;
	
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> str[i];

	
	sort(str,str+n, cmp);
	for (int i = 0; i < n; i ++)
		cout << str[i];
	
	return 0;
}

vue

监视

watch监视
还有停止监视

<template>
    <div class="person">
        <h1>情况一:监视ref的数据</h1>
        <h2>当前求和:{{ sum }}</h2>
        <button @click="changesum">click me</button>
    </div>    
</template>

<script setup>
import { ref, watch } from 'vue'
let sum = ref(0)
function changesum() {
    sum.value += 1
}
const stopwatch = watch(sum, (newValue, oldValue) => {
    console.log('sum变化',newValue, oldValue)
    if (newValue >= 10)
    {
        stopwatch()
    }
})

</script>

深度监视
如果修改的是ref定义的对象的属性,newValue, oldValue都是新的值,因为是同一个对象
如果修改整个ref定义的对象,就是一个新值一个旧值

watch(person, (newValue, oldValue) => {
    console.log('person变化',newValue, oldValue)
},{deep:true,immediate:true})

reactive默认开启深度监视

路由

还没弄好。。。

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

o_o O

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值