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. HIbernate與不支持boolean的數據庫之間的映射

    http://soft-development.iteye.com/blog/1225274 ————————————————————————————————————————————————————— ...

  2. Easyui Datagrid相同连续列合并扩展(三)

    function MergeCells(seletor, rows, fields) { if(rows == null || rows.length == 0 || fields == null | ...

  3. URL 重写

    转载自:http://www.cnblogs.com/knowledgesea/archive/2012/10/08/2715350.html 一. 为了页面更有利于seo优化,url重写程序需要做出 ...

  4. 30Mybatis_mybatis和spring整合-原始dao开发

    这篇文章很重要, 第一步:我们讲一下整合的思路: 我们以前要用Mybatis是需要sqlMapConfig.xml(这个配置文件需要配置dataource,以及mapper.xml文件.)sqlMap ...

  5. Loadrunner测试实例分析

    LoadRunner性能测试结果分析是个复杂的过程,通常可以从结果摘要.并发数.平均事务响应时间.每秒点击数.业务成功率.系统资源.网页细分图.Web服务器资源.数据库服务器资源等几个方面分析,如图1 ...

  6. ASP.NET MVC - The view must derive from WebViewPage, or WebViewPage<TModel>

    当通过一个空的站点构建ASP.NET MVC时经常会出现各种配置缺少的问题,最简单但的办法是吧VS自动生成的web.config文件拷贝到对应的目录下面 The view must derive fr ...

  7. Angular ContentChild

    contentchild // 使用方法 git clone https://git.oschina.net/mumu-osc/learn-component.git cd learn-compone ...

  8. Java线程之CompletionService批处理任务

    如果你向Executor提交了一个批处理任务,并且希望在它们完成后获得结果,怎么办呢? 为此你可以保存与每个任务相关联的Future,然后不断地调用 timeout为零的get,来检验Future是否 ...

  9. CSS解决图片缩小不变形

    我会在图片上加: <img style="max-width:80px;max-height:80px;"> 限制其最大宽度和高度

  10. 【BZOJ3438】小M的作物 最小割

    [BZOJ3438]小M的作物 Description 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物的种子,每种作物的种子 有1个(就是可以种一棵作物)(用1. ...