poj 1411 Calling Extraterrestrial Intelligence Again(超时)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 11211 | Accepted: 4356 | 
Description
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.
Input
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.
Output
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.
Sample Input
5 1 2
99999 999 999
1680 5 16
1970 1 1
2002 4 11
0 0 0
Sample Output
2 2
313 313
23 73
43 43
37 53
Source
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
#define N 100001
int prime[N];
bool check[N];
int n,a,b,m,tot;
int main(){
for(int i=;i<=N;i++)
if(!check[i]){
prime[n++]=i;
for(int j=i*;j<=N;j+=i)
check[j]=;
}
while(scanf("%d %d %d",&m,&a,&b)==&&m&&a&&b){
double adivb=a*1.0/b,tmp=;
int ansi,ansj;
for(int i=;i<n;i++){
for(int j=i;j<n;j++){
double t1=1.0*prime[i]*prime[j];
double t2=1.0*prime[i]/prime[j];
if(t1>tmp&&t1<=m&&t2>=adivb&&t2<=){
tmp=t1;ansi=i;ansj=j;
}
}
}
printf("%d %d\n",prime[ansi],prime[ansj]);
}
return ;
}
poj 1411 Calling Extraterrestrial Intelligence Again(超时)的更多相关文章
- 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 1239 Calling Extraterrestrial Intelligence Again (暴力枚举)
		
Calling Extraterrestrial Intelligence Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
 - HDUOJ-----(1329)Calling Extraterrestrial Intelligence Again
		
Calling Extraterrestrial Intelligence Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
 - Calling Extraterrestrial Intelligence Again POJ 1411
		
题目链接:http://poj.org/problem?id=1411 题目大意:找两个素数p,q满足a/b<=p/q<=1 且p*q<=m,求p*q最大的一组素数对. 第一次想的是 ...
 - 【HDOJ】1239 Calling Extraterrestrial Intelligence Again
		
这题wa了很多词,题目本身很简单,把a/b搞反了,半天才检查出来. #include <stdio.h> #include <string.h> #include <ma ...
 - 【noi 2.7_413】Calling Extraterrestrial Intelligence Again(算法效率--线性筛素数+二分+测时)
		
题意:给3个数M,A,B,求两个质数P,Q.使其满足P*Q<=M且A/B<=P/Q<=1,并使P*Q最大.输入若干行以0,0,0结尾. 解法:先线性筛出素数表,再枚举出P,二分出对应 ...
 - 穷举(四):POJ上的两道穷举例题POJ 1411和POJ 1753
		
下面给出两道POJ上的问题,看如何用穷举法解决. [例9]Calling Extraterrestrial Intelligence Again(POJ 1411) Description A mes ...
 - POJ 1411
		
#include<iostream> #include<stdio.h> #include<math.h> #define MAXN 50000 using nam ...
 - 转载:hdu 题目分类 (侵删)
		
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
 
随机推荐
- Engine中如何实现先居中显示要素再闪烁
			
[解决办法]:需要在要素居中显示之后.闪烁之前执行IScreenDisplay.UpdateWindow强制全刷,如: //居中显示要素 IActiveView actView = axMapCont ...
 - teambition的热血团队
			
一群热血年轻人开发了一套项目协作软件teambition,无意帮他们宣传,更多见网址www.teambition.com. 网站上简短的一段话,深深的打动了我.他们说teambition: 由热爱工作 ...
 - Unable to start activity ComponentInfo{com.first/com.first.Game}
			
原因一: xxx的错误,若为R.layout.main 那么应该是main.xml文件中的标签 使用错误,最常见的而且编译器不会提示的错误就是 android:name 和android:id 两者 ...
 - 【转】android shape的使用
			
shape用于设定形状,可以在selector,layout等里面使用,有6个子标签,各属性如下: <?xml version="1.0" encoding="ut ...
 - OC登陆界面登陆按钮动画
			
1.原作者:@entotsu 1.1 原作者连接:https://github.com/entotsu/TKSubmitTransition 2.使用: import "HyTransiti ...
 - iOS多线程-01-pthread与NSTread
			
简介 恰当的使用多线程编程可以提供任务的执行效率和系统资源的利用率 多线程是为了提高资源利用率,和应用程序的响应速度,多个线程共享应用资源 每个应用程序都有一个主线程,通常用来做UI界面刷新等 比较耗 ...
 - Java眼中的XML--文件读取--2 应用SAX方式解析XML
			
1.获取一个SAXParserFactory的实例.2.通过factory获取SAXParser实例. 3.新建一个包和继承自DefaultHandler的类. 因为SAX遍历方式,比如便利一个节 ...
 - find / -name *.py  | xargs grep "domain" | wc -l
			
http://world77.blog.51cto.com/414605/209125 http://blog.csdn.net/windone0109/article/details/2817792 ...
 - SharePoint 指定配置数据库访问账户“域账户\用户”
			
大家在安装sharepoint时都会遇到这个问题,域账户,什么是域账户哪?域账户简单理解就是网路账户,与本地账户不同,什么是域哪?域就是控制器. 一台Windows 计算机,它要么隶属于工作组,要么隶 ...
 - JDK自带工具一览表。妈妈再也不用担心你到处去下载小软件了~~
			
原来JDK早早就给我准备好了要用到的工具..反编译,JVM性能监视.诊断. JDK(Java Development Kit)是Java程序员最核心的开发工具,没有之一. JDK是一个功能强大的Jav ...