poj1338--poj2545--poj2591--打表
来源:互联网 发布:windows ping命令 编辑:程序博客网 时间:2024/05/16 11:27
http://poj.org/problem?id=1338
http://poj.org/problem?id=2545
http://poj.org/problem?id=2591
三道水题~~~~题目链接在上:
题意很容易理解,解法需要想一想,
即通过维护三个队列,来产生一个带有ans到数组。
以下是代码:
poj1338:
#include <cstdio>#include <algorithm>using namespace std;const int maxnum=1500;int a[1500]={1};int main(){ int m=1,n,i=0,j=0,k=0; for(;m<maxnum;) { a[m++]=min(a[i]*2,min(a[j]*3,a[k]*5)); if(a[m-1]==a[i]*2) ++i; if(a[m-1]==a[j]*3) ++j; if(a[m-1]==a[k]*5) ++k; } while(~scanf("%d",&n),n) printf("%d\n",a[n-1]); return 0;}
poj2545:
#include <iostream>#include <algorithm>using namespace std;typedef long long ll;ll a[10000100]={1};int main(){ ll p1,p2,p3,m; while(cin>>p1>>p2>>p3>>m) { int i=0,j=0,k=0,n; for(n=1;n<=m;) { a[n++]=min(a[i]*p1,min(a[j]*p2,a[k]*p3)); if(a[n-1]==a[i]*p1) ++i; if(a[n-1]==a[j]*p2) ++j; if(a[n-1]==a[k]*p3) ++k; } cout<<a[n-1]<<endl; } return 0;}
poj2591:
#include <cstdio>using namespace std;const int maxnum=10000100;int a[maxnum]={1};int main(){ int *x1=a,*x2=a,i; int temp1,temp2; for(i=1;i<maxnum;) { temp1=2**x1+1,temp2=3**x2+1; if(temp1<temp2) a[i++]=temp1,x1++; else if(temp1>temp2) a[i++]=temp2,x2++; else a[i++]=temp1,x1++,x2++; } int n; while(~scanf("%d",&n)) printf("%d\n",a[n-1]); return 0;}
- poj1338--poj2545--poj2591--打表
- poj1338 poj2591 poj2545 这三道题
- 多式子递推poj2545 poj2591 poj1338
- 转一篇好文:poj1338 poj2591 poj2545 这三道题
- POJ1338 & POJ2545 & POJ2591 & POJ2247 找给定规律的数
- poj1338 ugly number 题解 打表
- POJ2591
- poj2591
- POJ2591
- poj2545
- poj2545
- poj1338
- poj1338
- POJ1338
- poj1338
- poj1338
- poj1338
- POJ1338||POJ2247
- NSTimer的暂停与恢复
- 玩转Google开源C++单元测试框架Google Test系列(gtest)(总)
- Oracle 数据库启动命令dbstart没有反应
- frame、bounds、center
- 解决或者设置电脑来电开机的方式。
- poj1338--poj2545--poj2591--打表
- 新手上路之Hibernate(二):基本映射以及一些原则与主键生成策略
- 卢前 《本事》
- 以压缩包的形式对文件夹进行加密和解密
- Struts2通用标签之数据标签
- buffer cache
- 12个高矮不同的人排成两排
- Oracle数据库错误 ORACLE not available 解决方法
- x264 小技巧