• POJ 2545+2591+2247+1338简单水题


    【题意简述】:就是有这种一个序列。就拿当p1 = 2,p2 = 3, p3 = 5,来举例。由这三个数为基准组成的序列是:

    2,3,4,5,6,8,9,10,12……如今给你这个序列数组的下标,让你求得这个数组中,这个下标里的数是多少。

    【分析】:2,3,4,5,6,8,9,10,12……这个序列式由2,3,5这三个数生成的,详细怎样生成,就是:

    详见代码:

    这里以POJ2545为例:

    //弄清当中的逻辑关系,能够从最简单的2,3,5试着做起! 
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
    	long long p1,p2,p3;
    	int n;
    	long long H[100005];
    	int a1,a2,a3;
    	
    	while(cin>>p1>>p2>>p3>>n)
    	{
    		H[1] = 1;
    		a1=a2=a3=1;
    		for(int i = 2;i<=n+1;i++)
    		{
    			H[i] = min(p1*H[a1],min(p2*H[a2],p3*H[a3]));
    			if(H[i]==p1*H[a1])  a1++;
    			if(H[i]==p2*H[a2])  a2++;
    			if(H[i]==p3*H[a3])  a3++;
    		}
    		cout<<H[n+1]<<endl;
    	}
    	return 0;
    }

    另外三道题与这个相差无几,都是这个的变形

    仅仅只是2247 注意输出的格式!

    //  C++ 代码 题目本身非常easy。注意格式输出。!
     
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    
    int main()
    {
    	int a1,a2,a3,a4;
    	int n;
    	long long humble[6000];
    	humble[1]=1;
    	a1=1;
    	a2=1;
    	a3=1;
    	a4=1;
    	for(int i=2;i<=5842;i++)
    	{
    		humble[i] = min(2*humble[a1],min(3*humble[a2],min(5*humble[a3],7*humble[a4])));
    		if(humble[i]==2*humble[a1])
    			a1++;
    		if(humble[i]==3*humble[a2])
    			a2++;
    		if(humble[i]==5*humble[a3])
    			a3++;
    		if(humble[i]==7*humble[a4])
    			a4++;	
    	}
    	//string b;
    	while(1)
    	{
    		cin>>n;
    		if(n==0)
    			break;
    		if(n%10==1)
    		{
    			if(n%100==11)
    				cout<<"The "<<n<<"th"<<" humble number is "<<humble[n]<<"."<<endl;
    			else
    				cout<<"The "<<n<<"st"<<" humble number is "<<humble[n]<<"."<<endl;
    		}
    			
    		if(n%10==2)
    		{
    			if(n%100==12)
    				cout<<"The "<<n<<"th"<<" humble number is "<<humble[n]<<"."<<endl;
    			else
    				cout<<"The "<<n<<"nd"<<" humble number is "<<humble[n]<<"."<<endl;
    		}
    			
    		if(n%10==3)
    		{
    			if(n%100==13)
    				cout<<"The "<<n<<"th"<<" humble number is "<<humble[n]<<"."<<endl;
    			else
    				cout<<"The "<<n<<"rd"<<" humble number is "<<humble[n]<<"."<<endl;
    		}
    			
    		if(n%10>3||n%10==0)
    			cout<<"The "<<n<<"th"<<" humble number is "<<humble[n]<<"."<<endl;
    			
    	}
    }

    POJ  2591


    // 39392K  141Ms
    // 打表过得 =_= 
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int S[10000001];
    
    int main()
    {
    	int a,b,n;
    	S[1] = 1;
    	a = b = 1;
    	for(int i = 2;i<=10000000;i++)
    	{
    		S[i] = min(2*S[a]+1,3*S[b]+1);
    		if(S[i] == 2*S[a]+1) a++;
    		if(S[i] == 3*S[b]+1) b++;
    	}
    	while(cin>>n)
    	{
    		cout<<S[n]<<endl;
    	}
    	return 0;
    }


  • 相关阅读:
    linux 查找最后几条数据
    O(n) 取得数组中每个元素右边最后一个比它大的元素
    O(n) 取得数组中每个元素右边第一个比它大的元素
    位运算实现整数运算
    随手练——P1141 01迷宫
    迷宫寻路问题全解
    N皇后问题 各种优化
    八数码问题(三种解决办法)
    随手练——Uva-11584 划分成回文串(区间DP)
    【2016蓝桥杯省赛】试题C++ B组试题
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6869160.html
Copyright © 2020-2023  润新知