这道题比赛中没做出来,赛后搞了好久才出来的,严重暴露的我薄弱的数学功底,

这道题要推公式的,,,有类似于1*a+2*a^2+3*a^3+...+n*a^n的数列求和。

最后画了一张纸才把最后的结果推出来。::(x*M^x)/N.

而且通过这道题我发现有些数学函数还不如直接循环来的快

例如这道题中求x的值的时候。

【我在此收回前面的话,昨天是oj的问题,今天我又交了一遍log的代码,耗时变成了0ms了。。。OMG】

方法一:

int x = int(log(n)/log(m)+0.5);

        if(_pow(m,x)<n) x += 1;

耗时15ms

方法二:

int x;

        for(x = 1; ; ++x)

            if(_pow(m,x)>=n)

                break;

耗时0ms



代码如下:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <algorithm> #define LL long long
#define M 10005
#define N 15 using namespace std; int n, m;
LL _pow(LL a, LL b)
{
if(b==0) return 1;
LL ans = _pow(a,b/2);
if(b&1) return ans*ans*a;
else return ans*ans;
}
LL gcd(LL a, LL b)
{
return b==0?a:gcd(b,a%b);
}
int main ()
{
int t, k = 0;
scanf("%d",&t);
while(t--)
{
scanf("%d%d", &n, &m);
int x;
for(x = 1; ; ++x)
if(_pow(m,x)>=n)
break;
LL a = _pow(m,x)*x;
LL b = n;
LL g = a>b?gcd(a,b):gcd(b,a);
printf("Case %d: %I64d/%I64d\n", ++k, a/g, b/g);
}
return 0;
}

hdu - 3959 Board Game Dice(数学)的更多相关文章

  1. HDU 5955 Guessing the Dice Roll

    HDU 5955 Guessing the Dice Roll 2016 ACM/ICPC 亚洲区沈阳站 题意 有\(N\le 10\)个人,每个猜一个长度为\(L \le 10\)的由\(1-6\) ...

  2. hdu 5955 Guessing the Dice Roll 【AC自动机+高斯消元】

    hdu 5955 Guessing the Dice Roll [AC自动机+高斯消元] 题意:给出 n≤10 个长为 L≤10 的串,每次丢一个骰子,先出现的串赢,问获胜概率. 题解:裸的AC自动机 ...

  3. HDU 4586 Play the Dice(数学期望)

    Play the Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  4. HDU 4586 Play the Dice (数学,概率,等比公式,极限)

    题意:给你一个n面的骰子每个面有一个值,然后其中有不同值代表你能获得的钱,然后有m个特殊的面,当你骰到这一面的时候可以获得一个新的机会 问你能得到钱的期望. 析: 骰第一次     sum/n 骰第二 ...

  5. HDU 5902 GCD is Funny 数学

    GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...

  6. 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】

    Pokémon GO Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  8. hdu 1577 WisKey的眼神 (数学几何)

    WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. hdu 4586 Play the Dice 概率推导题

    A - Play the DiceTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

随机推荐

  1. C/C++中的指针数组和数组指针

    1. 指针数组 定义:int *p[n],由于[]的优先级高于*,p和[]结合成一个数组,该数组的元素存储的是int类型的指针,由于数组内容是指针,因此p+1的步长是sizeof(int*),在32位 ...

  2. (转)这个API很“迷人”——新的Fetch API

    原文:https://hacks.mozilla.org/2015/03/this-api-is-so-fetching 原标题是This API is So Fetching,Fetching也可以 ...

  3. java, poi, excel

    工作需要用java操作Excel,现在网上搜索了一下,决定选取POI包来操作.pom内容如下: <dependency> <groupId>org.apache.poi< ...

  4. CSS盒子模型学习记录1

    http://www.blueidea.com/tech/web/2007/4545.asp 代码试验: html代码: <!DOCTYPE html PUBLIC "-//W3C// ...

  5. x265编译

    x265 HEVC Encoder Mission Statement Online documentation Mailing list x265-devel@videolan.org HOWTO  ...

  6. 文章“Redcing the Dimensiongality of Data with Neural Networks”的翻译

    注明:本人英语水平有限,翻译不当之处,请以英文原版为准,不喜勿喷,另,本文翻译只限于学术交流,不涉及任何版权问题,若有不当侵权或其他任何除学术交流之外的问题,请留言本人,本人立刻删除,谢谢!! 本文原 ...

  7. 【229】Raster Calculator - 栅格计算器

    参考:分段函数进行复制,利用语句 参考:ArcGIS栅格计算器 - CSDN 参考:ArcGIS栅格计算器con条件函数使用 参考:ArcGIS栅格计算器 - 电脑玩物 ("lyr" ...

  8. delegate事件绑定

    为了代码的健壮性,绑定事件之前先解绑再进行绑定. var _$div = $("#id");_$div.undelegate("click mouseover mouse ...

  9. css属性word-spacing和letter-spacing的区别

    word-spacing和letter-spacing用来定义单词或者字母之间的水平空白间隔.顾名思义,word-spacing定义了单词之间的空白,例如: <div style="w ...

  10. jQuery 3.1.1 官方下载地址

    https://code.jquery.com/jquery-3.1.1.jshttps://code.jquery.com/jquery-3.1.1.min.js    打包下载:  http:// ...