东华复试OJ二刷复盘2

题22:假设有k个人质和k个绑匪围成一圈。人质的编号从1到k,绑匪的编号从k+1到2k。从编号1开始,每次从其中选出第m个人(隔m-1选出一人)出列。希望求出m的最小值,使得最先出列的k个人都是绑匪,即都是编号从k+1到2k的人。

cpp 复制代码
#include <bits/stdc++.h>

using namespace std;

bool Yue(vector<int> n,int shu){
    int count = 0;
    int index = 0;
    while(count < n.size()/2){//循环n次
        int singleCount=0;
        while(singleCount<shu){
            if(n[index]==0){
            	singleCount++;
			}
			index = (index + 1)%n.size();
        }
         index = (index - 1 + n.size()) % n.size();

        if(index<n.size()/2)return false;
        else n[index]=1;
        count++;
    }
    return true;
}



int main(){
    int num;
    while(cin>>num){
        vector<int> people(2*num,0);
        for(int i=num;;i++){
            if( Yue(people,i) ){
                cout<<i<<endl;
                break;
            }
        }
    }
}
  • 超时
  • 每次数位置都是先计数再后移再判断下次循环,缺少了循环后后移回原来位置的语句 index = (index - 1 + n.size()) % n.size();

题25:某商店规定:三个空汽水瓶可以换一瓶汽水,允许借一瓶换一瓶。如果小张手上有n个空汽水瓶,最多可以换多少瓶汽水喝?

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main(){
    int num=0;
    while(cin>>num){
        if(num==0)break;
        int ans=0;
        while(num>=3){
            int NewBottle = num/3;
            ans += NewBottle;
            num -= NewBottle*3;//换掉空瓶子
            num += NewBottle; //喝的新瓶子
        }
        if(num==2)ans++;//还可以借一个
        cout<<ans<<endl;
    }

    return 0;
    
}
  • 错误之处:用ans += num/3,并用num与ans做运算,但是ans是累积得到的汽水数,而不是当前一轮的汽水数。

  • 程序设计要区分循环运算变量num和累积变量ans,不能混淆计算。

题26:你的任务是找到阶乘最后面的非零位。举个例子,5!=1*2*3*4*5=120所以5!的最后面的非零位是2,7!=1*2*3*4*5*6*7=5040,所以最后面的非零位是4。

cpp 复制代码
#include <bits/stdc++.h>

using namespace std;

int CountNum25(int num,int redix){
	int ans=0;
	while(num%redix==0){
		ans++;num/=redix;
	}
	return ans;
}

int main(){
    int n;
    cin>>n;
    int count2=0,count5=0;//乘数中的2和5的个数
    int ans=1;
    for(int i=2;i<=n;i++){
        int num=i;
        count2+=CountNum25(num,2);
        count5+=CountNum25(num,5);
        while(num%2==0)num/=2;
        while(num%5==0)num/=5;
        ans*=num;
        ans = ans%10;
    }
    
    if(count2>count5){
        for(int i=0;i<(count2-count5);i++){
        	ans*=2;ans = ans%10;
		}
    }
    else if(count2<count5)for(int i=0;i<count5-count2;i++)ans*=5;ans = ans%10;
    cout<<ans%10;
    
    system("pause");
}
  • 粗心了,最后乘回多余2的时候没有取余,以为int够大,但是输出0,检查了好一会的逻辑,实际上是溢出了输出0

A potential issue with this encoder--decoder approach is that a neural network needs to be able to compress all the necessary information of a source sentence into a fixed-length vector. This may make it difficult for the neural network to cope with long sentences, especially those that are longer than the sentences in the training corpus. Cho et al. (2014b) showed that indeed the performance of a basic encoder--decoder deteriorates rapidly as the length of an input sentence increases.

  • corpus 语料库
  • 编码-解码器的方法有一个潜在的问题是神经网络需要能够将源语句的所有必要信息压缩成固定长度的向量。这可能让神经网络难以处理长句子,特别是那些比语料库里的句子更长的句子。Cho展示了基础编码-解码器的性能随着一个输入句子长度的增加而不断恶化。

In order to address this issue, we introduce an extension to the encoder--decoder model which learns to align and translate jointly. Each time the proposed model generates a word in a translation, it (soft-)searches for a set of positions in a source sentence where the most relevant information is concentrated. The model then predicts a target word based on the context vectors associated with these source positions and all the previous generated target words.

  • 为了处理这一问题,我们引入了编码-解码器模型的一个 扩展,该扩展 学习将对齐与翻译过程联合起来进行 对齐和联合翻译。每次提出的模型产出一个单词的翻译,它会搜索一组 最相关的浓缩信息在源句子中的位置 坐标集。然后模型基于与上下文向量来预测目标单词,上下文向量与这些源坐标和所有先前已生成的目标单词相关联。
相关推荐
明月_清风9 分钟前
从二叉树到 B+ 树:一文搞懂工程中「树」的演化之道
数据结构·算法·go
渡我白衣12 分钟前
并查集:基础认识与模拟实现
android·java·javascript·数据结构·c++·算法·并查集
hetao173383729 分钟前
2026-09-01~09-04 hetao1733837 的刷题记录
c++·算法
Evand J1 小时前
【MATLAB例程,图像滤波5】 反谐波均值滑动窗口滤波(CHMF)图像降噪与质量评价,附代码下载链接
图像处理·算法·计算机视觉·matlab·均值算法·滑动窗口滤波·均值滑动
血小板要健康1 小时前
链表 阶段算法总结
java·数据结构·笔记·算法·leetcode·链表
a187927218311 小时前
【算法】回溯算法(三):三记重锤与 N 皇后——记忆化、状态设计与三层漏斗
算法·leetcode·go·剪枝·回溯·n皇后·算法讲解
HugoStudio_SWAN3 小时前
洛谷 P1420 / P1179 / B4262 最长连号、数字统计与词频统计——统计的三种面孔
c++·学习·程序人生·算法
青 春 记 忆4 小时前
LeetCode 350. 两个数组的交集 II|Python 解法详解
python·算法·leetcode
阳明山水5 小时前
销量预测2025—2026:从模型竞赛到系统融合的范式转型
人工智能·深度学习·算法·机器学习·架构
桐盛科技5 小时前
拒绝“漂绿”风险:基于边缘计算的碳排放数据清洗算法与实时校验逻辑
人工智能·算法·边缘计算