东华复试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.

  • 为了处理这一问题,我们引入了编码-解码器模型的一个 扩展,该扩展 学习将对齐与翻译过程联合起来进行 对齐和联合翻译。每次提出的模型产出一个单词的翻译,它会搜索一组 最相关的浓缩信息在源句子中的位置 坐标集。然后模型基于与上下文向量来预测目标单词,上下文向量与这些源坐标和所有先前已生成的目标单词相关联。
相关推荐
青少儿编程课堂2 分钟前
蓝桥杯青少组·全国青少年信息素养·电子学会Scratch考级:校园智能抢答器项目解析
c++·python·算法·bfs·信息学竞赛
SZYSK5 分钟前
一套人员主数据,三套事务:通行、消费、人证比对如何分事件类型
物联网·算法·harmonyos
怕浪猫36 分钟前
不用摄像机,我把历史故事做成竖屏视频
算法·面试·github
郝学胜-神的一滴1 小时前
AI 编程智能体 16:从零基础搭建到精细化优化
人工智能·python·算法·语言模型·langchain·pip
喜欢打篮球的普通人1 小时前
AI 编译器内存分配算法:从静态/动态划分到内存复用
人工智能·算法
mjhcsp2 小时前
Code date creation v8.0 竞赛数据生成与对拍实战指南
算法·ai·深度优先·cdc
小郎君6583 小时前
keep-alive 页面怎么“真刷新”?别改外层 key——一个 refreshVersion 的完整实现
vue.js·算法
瑶池酒剑仙3 小时前
C++变量初始化五法完全指南:默认/拷贝/直接/列表/值初始化与窄化转换陷阱(青云之志)
c语言·开发语言·数据结构·c++·算法·visual studio
用户238003099453 小时前
从零开始实现扫雷游戏(C 语言控制台版)
算法
国科安芯3 小时前
星上计算的第一道防线:低轨遥感卫星载荷处理链中的AS32S601型抗辐射MCU—— 面向高分辨率成像与在轨智能处理的场景化综述
大数据·网络·人工智能·单片机·算法·低轨卫星·抗辐射