1011. Conductors

Time limit: 2.0 second
Memory limit: 64 MB

Background

Everyone making translations from English to Russian knows an English phrase "Naked conductor runs along the bus". It has two very different meanings.

Problem

Every bus in the Ekaterinburg city has a special man (or woman) called conductor. When you ride the bus, you have to give money to the conductor. We know that there are more than P% conductors and less than Q% conductors of all citizens of Ekaterinburg. Your task is to determine a minimal possible number of Ekaterinburg citizens. By percentage, we know that there are more than P% conductors and less than Q% conductors of all Russian citizens in this city

Input

Two numbers P,Q such that 0.01 ≤ PQ ≤ 99.99. Numbers are given with 2 digits precision. These numbers are separated by some spaces or "end of line" symbols.

Output

The minimal number of Ekaterinburg citizens.

Sample

input output
13
14.1
15

Notes

If there are 15 citizens and 2 conductors among them in Ekaterinburg, then there are 13 1/3 % conductors of all citizens.
Problem Source: USU Championship 1997
 
初步想法:从 1 开始遍历,当 n/p 和 n/q 之间存在整数,则所夹最小整数就是所求结果了。但下面的程序 floor 、 ceil 、 fabs 太耗时间了,虽然在自己电脑上都是秒出,但在评测机上达到了 2s 多,华丽丽 TLE。
#include <stdio.h>
#include <math.h>
#include <stdlib.h> int main(){
long n=0;
double p,q,tp,tq;
scanf("%lf%lf",&p,&q);
p/=100.0;q/=100.0;
while(++n){
tp=floor(n/p);
tq=ceil(n/q);
if(fabs(tq-tp)<1E-2) break;
//if(tp>tq) break;
//if(tp<tq) continue;
}
printf("%.0f",tp);
return 0;
}
​改进:整个算法就循环最耗时间了,有针对性地修改即可,直接 long 强转只保留整数部分,于是考虑:
​  n/p n/q  强转 ->  tp  tq
  2.x  1.y                 2    1
  3.x  1.y                 3    1
  2.x  2.y                 2    2
可以看到上面就是小数直接夹着整数的情况成立条件是 tp > tq 。
#include <stdio.h>
#include <math.h>
#include <stdlib.h> const double e=1E-6;
int main(){
long n=0;
double p,q;
long tp,tq;
scanf("%lf%lf",&p,&q);
p/=100.0;q/=100.0;
while(++n){
//tp=long(n/p); //WA
//tq=long(n/q);
tp=long(n/p-e);
tq=long(n/q+e);
if(tq<tp) break;
}
printf("%ld\n",tq+1);
return 0;
}

Ural 1011. Conductors的更多相关文章

  1. URAL题解一

    URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...

  2. ACM-ICPC(11/8)

    URAL 1005 给定一些石头的重量,要求分成两个部分最相近.二进制暴力枚举. #include <bits/stdc++.h> using namespace std; ]; int ...

  3. SCNU 2015ACM新生赛初赛【1001~1011】个人解题思路

            题目1001:       大意:已知$n$个角色,$m$种怪物种族,$k$个怪物,给出一组角色编号,编号$P_{i}$的角色能肝死编号$i$的怪物,对于给定的一组怪物编号,为了打通关 ...

  4. poj 1011

    http://poj.org/problem?id=1011 这是一道POJ的搜索的题目,最开始确实难以理解,但做过一些搜索的题目后,也没那么难了. 大概题意就是,现在有N根木头,要拼成若干根木头,并 ...

  5. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  6. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  7. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  8. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  9. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

随机推荐

  1. javascript超过容器后显示省略号效果(兼容一行或者多行)

    javascript超过容器后显示省略号效果       在实际的项目中,由于文字内容的长度不确定性和页面布局的固定性,难免会出现文字内容超过div(或其他标签,下同)区域的情况,此时比较好的做法就是 ...

  2. jquery实现tab切换完整代码

    代码如下,保存到html文件打开: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  3. Myeclipse启动报错: Invalid 'log4jConfigLocation' parameter

    java.lang.IllegalArgumentException: Invalid 'log4jConfigLocation' parameter: class path resource [lo ...

  4. Java中, for循环经典例子

    循环的两种应用:穷举和迭代. break跳出整个循环 一.穷举:将所有可能的情况都走一遍,用if筛选出符合条件. 百鸡百钱: 一只公鸡1文钱,一只母鸡2文钱,一只小鸡半文钱,需要买100只鸡, 正好花 ...

  5. Windows下安装Nginx+php+mysql环境

    系统:Windows 7 64位系统 安装之前,首先下载软件: Nginx: http://nginx.org/en/download.html PHP Stable PHP 5.6.26: http ...

  6. 使用TabPageIndicator的样式问题

    在使用TabPageIndicator往往会出现一些样式问题,导致看不到字,下面是总结的步骤: 1.布局<LinearLayout xmlns:android="http://sche ...

  7. java静态方法调用&&构造函数&&静态块

    静态方法,也就是使用static声明的方法,在虚拟机启动加载类的时候就进行了创建,所以使用到静态方法时,直接使用类名点静态方法即可调用.java在执行静态方法前,不会调用构造函数:构造函数是在实例化j ...

  8. 美女jquery图片播放器插件

    相册在线查看http://keleyi.com/keleyi/phtml/image/6.htm 可全屏,可拖动,可自动播放的jquery图片展示插件 使用说明:1.引用css文件:<link ...

  9. 隐式启动判断是否有匹配的Intent

    一.PackageManager的resolveActivity public abstract ResolveInfo resolveActivity(Intent intent, int flag ...

  10. Core Data的一些常见用法

    一.简介 Core Data是一个纯粹的面向对象框架,其本质就是一个ORM(对象关系映射:Object Relational Mapping),能以面向对象的方式操作SQLite数据库.在实际开发中绝 ...