POJ 2545+2591+2247+1338简单水题
来源:互联网 发布:广电网络宽带电话 编辑:程序博客网 时间:2024/05/16 19:51
【题意简述】:就是有这样的一个序列,就拿当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++ 代码 题目本身很简单,注意格式输出!! #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;elsecout<<"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;elsecout<<"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;elsecout<<"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;}
0 0
- POJ 2545+2591+2247+1338简单水题
- poj 2739 简单题
- 简单搜索poj 2243(水
- POJ-1029简单推断题
- POJ 1006 数论简单题
- hdu,poj博弈简单题
- POJ-1118-简单暴力题
- POJ 2498 StuPId(简单题)
- POJ 3094 Quicksum(简单题)
- poj 1281(简单模拟题)
- POJ-----1321搜索简单题
- poj 2485 (Prim简单题)
- POJ丑数DP题汇总2591 1338 2247 2545
- POJ 1061 && POJ 2142 两道扩展欧几里得简单题
- 优先队列简单三题:POJ3253 POJ 2431 POJ 3614
- poj 2411(插头DP 简单题)
- poj-1004 简单题,学习输入输出格式
- POJ 3254 状态压缩DP简单题
- 使用Visual Studio在标准Web Part 部件中创建事件处理器
- c++程序设计
- 网络--- tcp状态总结
- PB调用oracle存储过程
- HTTPS那些事(一)HTTPS原理
- POJ 2545+2591+2247+1338简单水题
- hibernate中的几种映射
- html中插入视频和jquery动态修改视频
- HTTPS那些事(二)SSL证书
- C和指针开头的程序
- 检索 COM 类工厂中 CLSID 为{00024500-0000-0000-C000-000000000046} 的组件时失败,报错误 80070005
- 基于BP神经网络的2014世界杯比分预测
- Android TextView 实现文字大小不同和文字颜色不同
- PHP中超全局变量$GLOBALS和global的区别