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 ...
随机推荐
- There is no Action mapped for namespace [/] and action name [updateUser] associated with context path [].
在使用Struts2的时候,遇到了这个问题. 原因分析: 找不到指定的路径, 那么就是struts.xml的内容问题, 或者是struts.xml的文件位置存在问题. struts2默认是应该放在sr ...
- PHP12 文件操作
学习要点 文件系统概述 目录基本操作 文件基本操作 文件上传下载 文件上传类的设计 文件系统概述 概述 PHP文件系统的操作是基于UNIX系统模型,所以有一些文件处理函数无法在windows服 ...
- 删除mysql中user为空用户,mysql空密码
进入mysql数据库 mysql -uroot -p 查看用户信息 select user,host ,Password from mysql.user; 如下图: 删除user为空用户 delete ...
- MySQL多版本并发控制(MVCC)
MVCC是行级锁的一个变种,但是它在很多的情况下避免了加锁操作,因此开销更低.MySQL,包括Oracle.PostgreSQL都实现了MVCC,虽然每个关系数据库实现不一样,但大都是实现了非阻塞的读 ...
- js实现复制粘贴功能
在项目中使用到复制粘贴功能,虽然网上有很多大牛封装了很多的插件,但是还是想不去使用插件,就像自己来实现这个功能. 另一篇是禁止复制粘贴 前端er怎样操作剪切复制以及禁止复制+破解等 初步想法: 1. ...
- vue 项目规范
1, 组件化 2, css 分清单独和通用的 3, 封装请求 4, 命名原则 1: 尽量和后端保持一致 2: 简单常见的单词 3: 全部小写
- 前端基础之CSS_1
摘要 CSS(层叠样式表)的三种设置方法 基本选择器 组合选择器 属性选择器 分组与嵌套 伪类选择器 伪元素选择器 选择器的优先级 一些样式的设置(字体.文本.背景.边框) display属性设置 0 ...
- C语言学习13
快速排序 //快速排序 #include <stdio.h> void quicksort(int a[], int left, int right); void main() { ] = ...
- 【BZOJ 1588】[HNOI2002] 营业额统计(Treap)
Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每 ...
- PTA 03-树2 List Leaves (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/666 5-4 List Leaves (25分) Given a tree, you ...