2018 autumn recruit blibli Algorithm Engineer

I give the code is as follows: Before doing the same and the number of towers (dp entry title) ideas

dp [i] [j] to come coordinates (i, j) of the minimum deceleration (only take up two cases the right and down)

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include <algorithm>
using namespace std;
const int maxn=1002;
int dp[maxn][maxn]; 
int main()
{int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	cin>>dp[i][j];
	
	for(int i=0;i<n;i++)//因为不走回头路所以最上面的一行和最左面一列只有一种情况 
	{
	for(int j=0;j<n;j++)
	{
	if(i==0&&j>=1)dp[i][j]+=dp[i][j-1];
	else if(j==0&&i>=1)dp[i][j]+=dp[i-1][j];
	else if(i>=1&&j>=1)	dp[i][j]+=min(dp[i][j-1],dp[i-1][j]);
	}
	}
//测试 
//	for(int i=0;i<n;i++)
//	{
//	for(int j=0;j<n;j++)
//	cout<<dp[i][j]<<" ";
//		cout<<endl;
//    }
cout<<dp[n-1][n-1]<<endl;

    return 0;
}

  

Personal code is as follows:

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
const int maxn=10005; 
int main()
{	
	string s1,s2;
	int ver1[maxn];//把版本数字分离出来放在数组中
	int ver2[maxn];
	cin>>s1>>s2;
	fill(ver1,ver1+maxn,0);
	fill(ver2,ver2+maxn,0);
	 int top1=0,top2=0;
	 int sum=0;
	for(int i=0;i<s1.size();i++)
	{
	
		if(s1[i]!='.')
		{	
			sum=sum*10+(s1[i]-'0'); 
		}
		if(s1[i]=='.'||i==s1.size()-1) 
		{
		ver1[top1]=sum;
		top1++;
		sum=0;
		}
		
	}sum=0;
	for(int i=0;i<s2.size();i++)
	{
		if(s2[i]!='.')
		{	
			sum=sum*10+(s2[i]-'0'); 
		}
		if(s2[i]=='.'||i==s2.size()-1) 
		{
		ver2[top2]=sum;
		top2++;
		sum=0;
		}
		
	}
	int f=0;
	for(int i=0;i<(top1>=top2? top1:top2);i++)
	{
		if(ver1[i]>ver2[i]) {
			f=1;break;
		}
		if(ver1[i]<ver2[i]){
			f=-1;break;
		}
		
	}cout<<f<<endl;
	
	
    return 0;
}

  

Problem-solving ideas: and before writing 1-n * n thinking about the same, but this time I have not put up a fence is plus access to an array of judge

code show as below:

#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=10005; 
int a[maxn][maxn];
bool vis[maxn][maxn]={false};//是否访问数组 

int main ()
{
	int m,n;//m行n列的矩阵 
	int i,j;
	int cnt=0;//计算输出元素个数 
    while(cin>>m&&cin>>n&&m!=-1&&n!=-1){
    	
    	for(i=0;i<m;i++)
    	for(j=0;j<n;j++)
    		cin>>a[i][j];
    	
		i=0;j=0;//初始化起点坐标 
		while(cnt<n*m) 
		{
		while(j<n&&!vis[i][j])//turn right 
		{
		cout<<a[i][j]<<(cnt==n*m-1? "":",");
		vis[i][j]=true;
		j++;cnt++;	
		}i++;j--;//和之前我写1-n*n填数是一样的 
		
		while(i<m&&!vis[i][j])//turn down 
		{
		cout<<a[i][j]<<(cnt==n*m-1? "":",");
		vis[i][j]=true;	
		i++;cnt++;		
		}i--;j--;
		
		while(j>=0&&!vis[i][j])//turn left
		{
		cout<<a[i][j]<<(cnt==n*m-1? "":",");
		vis[i][j]=true;		
		j--;cnt++;		
		}i--;j++;	
    	
    	while(i>=0&&!vis[i][j])//turn up
    	{
    	cout<<a[i][j]<<(cnt==n*m-1? "":",");
	vis[i][j]=true;	
    	i--;cnt++;		
	}i++;j++;
    	
       }
    	
    	
    	
	} 



}

  

 

Reproduced in: https: //www.cnblogs.com/cstdio1/p/11083964.html

Guess you like

Origin blog.csdn.net/weixin_34194087/article/details/94032162