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;
}
POJ 2545+2591+2247+1338简单水题的更多相关文章
- [POJ 1000] A+B Problem 经典水题 C++解题报告 JAVA解题报告
A+B Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 311263 Accepted: 1713 ...
- HDOJ(HDU) 2090 算菜价(简单水题、)
Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...
- POJ 1061 青蛙的约会 数论水题
http://poj.org/problem?id=1061 傻逼题不多说 (x+km) - (y+kn) = dL 求k 令b = n-m ; a = x - y ; 化成模线性方程一般式 : Lx ...
- 【UVA - 1644 / POJ - 3518】Prime Gap(水题)
Prime Gap 这里直接写中文了 Descriptions: 对于一个数n,若n为素数则输出0,否则找到距离n最小的两个素数,一个大于n,一个小于n,输出他们的差(正数) Input 多组输入 每 ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- 简单水题 POJ 2291 Rotten Ropes
题目传送门 /* 我校oj的源题,看懂题意就很水,贴出来省的再敲:) */ #include <cstdio> #include <algorithm> #include &l ...
- POJ 1936 All in All 匹配, 水题 难度:0
题目 http://poj.org/problem?id=1936 题意 多组数据,每组数据有两个字符串A,B,求A是否是B的子串.(注意是子串,也就是不必在B中连续) 思路 设置计数器cnt为当前已 ...
- POJ 3125 Printer Queue(队列,水题)
题意:有多组数据,每组数据给出n,m,n表示需要打印的文件个数,m表示要打印的目标位置(m为0~n-1). 接下来给出n个数,第i个值对应第i-1个位置的优先级大小. 打印规则如下: ...
- poj 1218 THE DRUNK JAILER【水题】
THE DRUNK JAILER Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25124 Accepted: 1576 ...
随机推荐
- 基于Ubuntu 14.04 LTS编译Android4.4.2源代码
转载自:雨水:http://blog.csdn.net/gobitan/article/details/24367439 基于Ubuntu 14.04 LTS编译Android4.4.2源代码 ...
- PHP19 PHPStorm2018和GitHub的使用
目的 使用GitHub的代码仓库进行项目代码托管. 准备工作 1.在GitHub注册账号 https://github.com/ 2.Start a Project 登陆后创建一个项目 3.创建版本仓 ...
- css 给div 添加滚动条样式hover 效果
css .nui-scroll { margin-left: 100px; border: 1px solid #000; width: 200px; height: 100px; ...
- 169. Majority Element@python
Given an array of size n, find the majority element. The majority element is the element that appear ...
- 天梯赛L1 题解
L1-001 Hello World (5 分) 这道超级简单的题目没有任何输入. 你只需要在一行中输出著名短句“Hello World!”就可以了. AC代码:(直接输出记性) #include & ...
- INFORMATION_SCHEMA InnoDB 表
INFORMATION_SCHEMA InnoDB Tables 本节提供InnoDB INFORMATION_SCHEMA表的表定义. 有关相关信息和示例,请参见"InnoDB INFOR ...
- 简单的自动化使用--使用selenium实现学习通网站的刷慕课程序。注释空格加代码大概200行不到
简单的自动化使用--使用selenium实现学习通网站的刷慕课程序.注释空格加代码大概200行不到 相见恨晚啊 github地址 环境Python3.6 + pycharm + chrom浏览器 + ...
- day22 02 面向对象的交互
day22 02 面向对象的交互 一.三种编程方式 1.面向过程编程:核心是过程,流水线式思维 优点:极大降低了写程序的复杂程度,只需要顺着要执行的步骤,堆叠代码即可 缺点:一套流水线或者流程就用来解 ...
- LINUX常用文件说明
一.网络配置 1.修改主机名 /etc/sysconfig/network或/etc/hosts 2.开启或关闭网卡 ifconfig eth0 down/up 3.linuxa下查看一个网卡绑定的所 ...
- 大数据学习——点击流日志每天都10T,在业务应用服务器上,需要准实时上传至(Hadoop HDFS)上
点击流日志每天都10T,在业务应用服务器上,需要准实时上传至(Hadoop HDFS)上 1需求说明 点击流日志每天都10T,在业务应用服务器上,需要准实时上传至(Hadoop HDFS)上 2需求分 ...