hdu 1239 Calling Extraterrestrial Intelligence Again (暴力枚举)
Calling Extraterrestrial Intelligence Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3993 Accepted Submission(s): 2097
We are planning a similar project. Your task in the project is to find the most suitable width and height of the translated rectangular picture. The term "most suitable" is defined as follows. An integer m greater than 4 is given. A positive fraction a / b less than or equal to 1 is also given. The area of the picture should not be greater than m. Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than a / b nor greater than 1. You should maximize the area of the picture under these constraints.
In other words, you will receive an integer m and a fraction a / b. It holds that m > 4 and 0 < a / b < 1. You should find the pair of prime numbers p, q such that pq <= m and a / b <= p / q <= 1, and furthermore, the product pq takes the maximum value among such pairs of two prime numbers. You should report p and q as the "most suitable" width and height of the translated picture.
The integers of each input triplet are the integer m, the numerator a, and the denominator b described above, in this order. You may assume 4 < m <= 100000 and 1 <= a <= b <= 1000.
Each output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output.
99999 999 999
1680 5 16
1970 1 1
2002 4 11
0 0 0
313 313
23 73
43 43
37 53
Eddy
题意:
给你一个大于4的整数m和一个真分数a/b,求最佳素数对p、q,使得a/b<=p/q<=1且pq<=m。最佳即为满足条件的pair中pq最大的一对。
感想:
关于素数打表的各种方法还是要好好研究一下。。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 100005
using namespace std; bool no_prim[N];
int m,a,b,p,q; void primetable()
{
int i,j;
for(i=3;i<317;i+=2)
{
if(no_prim[i]==false)
{
int tmp=i<<1;
for(j=i*i;j<N;j+=tmp)
no_prim[j]=true;
}
}
} int main()
{
int i,j;
primetable();
while(scanf("%d%d%d",&m,&a,&b)&&m&&a&&b)
{
p=q=0;
double limit=a*1.0/b;
for(i=2;i<=m;i++)
{
if(!no_prim[i]&&i%2!=0||i==2)
{
for(j=2;j<=i&&i*j<=m;j++)
{
if(!no_prim[j]&&j%2!=0||j==2)
{
if(j*1.0/i>=limit&&i*j>p*q) //i和j的顺序
{
p=j;
q=i;
}
} }
}
}
printf("%d %d\n",p,q);
}
return 0;
}
hdu 1239 Calling Extraterrestrial Intelligence Again (暴力枚举)的更多相关文章
- 【HDOJ】1239 Calling Extraterrestrial Intelligence Again
这题wa了很多词,题目本身很简单,把a/b搞反了,半天才检查出来. #include <stdio.h> #include <string.h> #include <ma ...
- poj 1411 Calling Extraterrestrial Intelligence Again(超时)
Calling Extraterrestrial Intelligence Again Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- HDUOJ-----(1329)Calling Extraterrestrial Intelligence Again
Calling Extraterrestrial Intelligence Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- poj 1411 Calling Extraterrestrial Intelligence Again
题意:给你数m,a,b,假设有数p,q,满足p*q<=m同时a/b<=p/q<=1,求当p*q最大的p和q的值 方法:暴力枚举 -_-|| and 优化范围 我们可以注意到在某一个m ...
- HDU - 1248 寒冰王座 数学or暴力枚举
思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...
- hdu 4082 Hou Yi's secret(暴力枚举)
Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5944 Fxx and string(暴力/枚举)
传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Othe ...
- hdu 4968 Improving the GPA (水 暴力枚举)
题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10, ...
- HDU 5660 jrMz and angles (暴力枚举)
jrMz and angles 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/E Description jrMz has tw ...
随机推荐
- 五个项目管理学习笔记.沟通技巧II
两.通信模型:沟通的双向过程 沟通模型: 编 码---------------->信息-----------------> 解码&歧义 发送者 ...
- swiper实现触摸滑动
引入文件的必要性 <link href="css/swiper.min.css" rel="stylesheet" type="text/css ...
- hdu 5066 Harry And Physical Teacher(Bestcoder Round #14)
Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- centos6.5 x86_64安装oracle 11.2.0.3grid
centos6.5 x86_64安装oracle 11.2.0.3grid 1.安装前的准备 工作 1.1.配置node1 1.1.1.配置虚拟机并安装centos 安装node1----- 1 ...
- HDU 2544-最短路(最短路spfa)
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- PHP通过传递对象参数调用asp.net Webservice 服务
asp.net 测试服务 ProcessRequest.asmx文件代码 public class ProcessRequest : System.Web.Services.WebService ...
- hdu 5053 the Sum of Cube(上海网络赛)
the Sum of Cube Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Zepto
移动开发流量省起来之Zepto 事情是这样的:最近开发的一个手机网站客户反应访问起来特别慢,刷了半天才能看到页面,然后问我们是不是网站出问题了.于是我赶紧找了各种手机测试一下,没有问题,首先排除程序错 ...
- MVC验证10-到底用哪种方式实现客户端服务端双重异步验证
原文:MVC验证10-到底用哪种方式实现客户端服务端双重异步验证 本篇将通过一个案例来体验使用MVC的Ajax.BeginForm或jQuery来实现异步提交,并在客户端和服务端双双获得验证.希望能梳 ...
- ios 安装OpenFire
1.开发xmpp官网下载 2.打开openfire.pkg 3.点击继续 4.成功安装后打开偏好设置 ->双击poenfire->弹出窗体[好] 5.随后会弹出以下这个视图 开启 strr ...