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. Genesis2000使用c#开发脚本

    这是我自学程序以来在博客园的第一篇博客,如有不好的地方请大家指正,谢谢! 这边文章的目的是给予那些在PCB使用Genesis2000程序脚本开发的人员提供.net平台下的开发方法. 目前genesis ...

  2. 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果)

    [源码下载] 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果) 作者:webabcd 介绍背水一战 Windows 10 之 动画 ThemeTrans ...

  3. iPhone开发与cocos2d 经验谈

    转CSDN jilongliang : 首先,对于一个完全没有mac开发经验,甚至从没摸过苹果系统的开发人员来说,首先就是要熟悉apple的那一套开发框架(含开发环境IDE.开发框架uikit,还有开 ...

  4. Java字节、十进制、十六进制、字符串之间的相互转换

    1. 字节转10进制 直接使用(int)类型转换. /* * 字节转10进制 */ public static int byte2Int(byte b){ int r = (int) b; retur ...

  5. html&css中的文字对齐问题

    html&css的使用过程中,我们经常会遇到很多文字对齐问题.下面我要介绍一个有丁点难的文字对齐问题. 实现效果如下图所示.   两行长度不定的文字,要让它们总体水平居中,然后,这两行字要左对 ...

  6. NET IL命令查询器

    最近研究了一下IL代码,闲来无事,开发一个小工具,供大家使用.编程.破解,手头必备工具. 模糊搜索,可以把相关的命令都列出来.选中行,可以提示指令说明. 如果指令不全,可以增加指令及说明. CSDN下 ...

  7. c#模拟js escape方法

    public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...

  8. Spark on Yarn 学习(一)

    最近看到明风的关于数据挖掘平台下实用Spark和Yarn来做推荐的PPT,感觉很赞,现在基于大数据和快速计算方面技术的发展很快,随着Apache基金会上发布的一个个项目,感觉真的新技术将会不断出现在大 ...

  9. jQuery演示8种不同的图片遮罩层动画效果

    效果预览 下载地址 jQuery插件大全 实例代码 <div class="container"> <h1>jQuery图标和文章动画效果</h1&g ...

  10. 原生JS实战:写了个斗牛游戏,分享给大家一起玩!

    本文是苏福的原创文章,转载请注明出处:苏福CNblog:http://www.cnblogs.com/susufufu/p/5869953.html 该程序是本人的个人作品,写的不好,未经本人允许,请 ...