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

  • 为了处理这一问题,我们引入了编码-解码器模型的一个 扩展,该扩展 学习将对齐与翻译过程联合起来进行 对齐和联合翻译。每次提出的模型产出一个单词的翻译,它会搜索一组 最相关的浓缩信息在源句子中的位置 坐标集。然后模型基于与上下文向量来预测目标单词,上下文向量与这些源坐标和所有先前已生成的目标单词相关联。
相关推荐
不做无法实现的梦~7 小时前
运动控制系统复习一览-----常考题目总结版本
算法
小短腿的代码世界7 小时前
信号路由风暴:Qt算法交易系统的高频信号分发架构
qt·算法·架构
阿文的代码库7 小时前
一文读懂GROUP BY 1,2 VS GROUP BY column_1, column_2 的区别
算法
008爬虫实战录8 小时前
【码上爬】 题十:魔改算法 堆栈分析,找加密值过程详解
前端·python·算法
chao1898448 小时前
基于狮蚁群算法(ALO)的火电机组功能调度实现
人工智能·算法
Deep-w8 小时前
【MATLAB】含光伏 - 储能的家庭/工业微电网能量管理仿真研究
开发语言·算法·matlab
阿文的代码库9 小时前
换根技巧实例分析:最小高度树
算法·动态规划
dyxal9 小时前
Louvain 算法:让网络自己“报团取暖”的发现者
开发语言·算法
计算机安禾9 小时前
【c++面向对象编程】第41篇:函数模板与类模板:泛型编程的基石
开发语言·c++·算法
SilentSamsara9 小时前
属性查找顺序:实例 → 类 → 父类的完整 MRO
开发语言·python·算法·青少年编程