东华复试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 小时前
Hot 100 ---腐烂的橘子
java·数据结构·后端·算法·leetcode·广度优先
未来之窗软件服务2 小时前
计算机考试-快速排序—东方仙盟
数据结构·算法·排序算法·仙盟创梦ide·东方仙盟
小龙报2 小时前
【优选算法】1. 水果成蓝 2.找到字符串中所有字母的异位词
java·c语言·数据结构·数据库·c++·redis·算法
txzrxz3 小时前
数论:排列数、组合数、费马小定理、逆元、同余定理
c++·算法·数论·组合数·费马小定理·逆元·排列数
xqqxqxxq3 小时前
LeetCode Hot100 双指针专项题解笔记
笔记·算法·leetcode
闪电悠米3 小时前
力扣hot100-54.螺旋矩阵-模拟边界控制详解
算法·leetcode·矩阵
变量未定义~3 小时前
虚拟节点-星石传送阵(4星)、强连通分量
数据结构·算法
IT方大同4 小时前
C语言分支与循环语句
c语言·开发语言·算法
待磨的钝刨4 小时前
深入理解主成分分析(PCA)
人工智能·线性代数·算法·机器学习
wWYy.5 小时前
算法:合并两个有序数组
数据结构·算法