A: HDU5170

这题让比较a^b与c^d的大小。1<=a,b,c,d<=1000.

显然这题没法直接做,要利用对数来求,但是在math库中有关的对数函数返回的都是浮点数,所以这又要涉及到eps问题。

其它就没有什么需要注意的了,我用的是log()函数,当然还可以用log10().....,原理不变。

#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <stack>
#define inf 0x3f3f3f3f
#include <stdio.h>
#include <string.h>
typedef long long ll;
#define mod 10000007
#define eps 1e-9
using namespace std;
int a,b,c,d;
int main()
{
while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
{
if(b*log(a)-d*log(c)>eps)
printf(">\n");
else if(fabs(b*log(a)-d*log(c))<=eps)
printf("=\n");
else printf("<\n");
}
return ;
}

B:HDU5171

题目:按照规则扩展一个集合k次,然后求其总和。

【分析】

扩展规则很简单,就是一个斐波那契数列,但是如果按照模拟的方法手动推算,复杂度对于本题的数据范围来说是不太合适的。(1≤k≤1000000000)
可以利用矩阵快速幂来迅速完成。(矩阵快速幂可以完成任何递推公式)
                            [0, 1, 0] 
[f[n-1],f[n],s[n-1]]*[1, 1, 1] = [f[n],f[n+1],s[n]]
                            [0, 0, 1]
我第一次写完代码后验证结果是对的,但提交一直WA,之后发现在计算矩阵A的k+1次幂时,发现中间爆数据了,果断把int a[3][3]改成了 __int64 a[3][3],果断A了。
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
typedef __int64 ll;
#define mod 10000007
using namespace std;
struct ma
{
ll a[][];
}res,init;
int n,se[];
ll sum,k;
ma mult(ma x,ma y)
{
ma temp;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
temp.a[i][j]=;
for(int z=;z<;z++)
temp.a[i][j]=(temp.a[i][j]+x.a[i][z]*y.a[z][j])%mod;
}
}
return temp;
}
ma Pow(ma x,ll ke)
{
ma temp;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
temp.a[i][j]=(i==j);
}
}
while(ke)
{
if(ke&) temp=mult(x,temp);
ke>>=;
x=mult(x,x);
}
return temp;
}
int main()
{
while(scanf("%d%I64d",&n,&k)!=EOF)
{
sum=;
init.a[][]=,init.a[][]=,init.a[][]=;
init.a[][]=,init.a[][]=,init.a[][]=;
init.a[][]=,init.a[][]=,init.a[][]=;
for(int i=;i<n;i++)
{
scanf("%d",&se[i]);
}
sort(se,se+n);
for(int i=;i<n-;i++)
{
sum=(sum+se[i])%mod;
}
k+=;
res=Pow(init,k);
sum=(sum+(se[n-]*res.a[][])%mod+(se[n-]*res.a[][])%mod+(se[n-]*res.a[][])%mod)%mod;
printf("%I64d\n",sum);
}
return ;
}

BC#29A:GTY's math problem(math) B:GTY's birthday gift(矩阵快速幂)的更多相关文章

  1. HDU 5171 GTY's birthday gift 矩阵快速幂

    GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  2. HDU5171 GTY's birthday gift —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-5171 GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others)  ...

  3. BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)

    GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  4. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  6. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  7. HDU1757-A Simple Math Problem,矩阵快速幂,构造矩阵水过

    A Simple Math Problem 一个矩阵快速幂水题,关键在于如何构造矩阵.做过一些很裸的矩阵快速幂,比如斐波那契的变形,这个题就类似那种构造.比赛的时候手残把矩阵相乘的一个j写成了i,调试 ...

  8. A Simple Math Problem (矩阵快速幂)

    Lele now is thinking about a simple function f(x).  If x < 10 f(x) = x.  If x >= 10 f(x) = a0 ...

  9. hdu 1757 A Simple Math Problem (矩阵快速幂)

    Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 ...

随机推荐

  1. Dirichlet Distribution

    Beta分布: 二项式分布(Binomial distribution): 多项式分布: Beta分布: Beta分布是二项式分布的共轭先验(conjugate prior) Dirichlet Di ...

  2. sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)

    Clockwise Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...

  3. 【BZOJ2801】[Poi2012]Minimalist Security BFS

    [BZOJ2801][Poi2012]Minimalist Security Description 给出一个N个顶点.M条边的无向图,边(u,v)有权值w(u,v),顶点i也有权值p(i),并且对于 ...

  4. 【BZOJ4275】[ONTAK2015]Badania naukowe DP

    [BZOJ4275][ONTAK2015]Badania naukowe Description 给定三个数字串A,B,C,请找到一个A,B的最长公共子序列,满足C是该子序列的子串. Input 第一 ...

  5. 【BZOJ4883】[Lydsy2017年5月月赛]棋盘上的守卫 KM算法

    [BZOJ4883][Lydsy2017年5月月赛]棋盘上的守卫 Description 在一个n*m的棋盘上要放置若干个守卫.对于n行来说,每行必须恰好放置一个横向守卫:同理对于m列来说,每列 必须 ...

  6. 在centos linux上安装jdk7

    在这里下载jdk7rpm安装包,并上传到centos服务器上http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7- ...

  7. css3中的动画功能

    直接用我的一段代码演示下css3中实现动画效果的事例,让一个div自动旋转起来 代码如下: <!doctype html> <html lang="en"> ...

  8. 飘城旅游网pc,流式,响应式布局

    相关视频教程http://pan.baidu.com/s/1o77wirK 我的源码链接:http://pan.baidu.com/s/1czTsKI

  9. Code Forces 645B Mischievous Mess Makers

    It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in thei ...

  10. Cookies and Session Tracking Client Identification cookie与会话跟踪 客户端识别

    w HTTP The Definitive Guide Cookies can be used to track users as they make multiple transactions to ...