BC#29A:GTY's math problem(math) B:GTY's birthday gift(矩阵快速幂)
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次,然后求其总和。
【分析】
#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(矩阵快速幂)的更多相关文章
- HDU 5171 GTY's birthday gift 矩阵快速幂
GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU5171 GTY's birthday gift —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5171 GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others) ...
- 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 ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- HDU1757-A Simple Math Problem,矩阵快速幂,构造矩阵水过
A Simple Math Problem 一个矩阵快速幂水题,关键在于如何构造矩阵.做过一些很裸的矩阵快速幂,比如斐波那契的变形,这个题就类似那种构造.比赛的时候手残把矩阵相乘的一个j写成了i,调试 ...
- 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 ...
- 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 ...
随机推荐
- 10 部署应用程序和applet
跳过 09 Swing用户界面组件 JAR文件 在将应用程序进行打包时, 使用者一定希望仅提供给其一个单独的文件, 而不是一个含有大量类文件的目录, Java归档(JAR)文件就是为此目的而设计的. ...
- 三种CSS方法实现loadingh点点点的效果
我们在提交数据的时候,在开始提交数据与数据提交成功之间会有一段时间间隔,为了有更好的用户体验,我们可以在这个时间段添加一个那处点点点的动画,如下图所示: 汇总了一下实现这种效果主要有三种方法: 第一种 ...
- ci 框架插入时返回插入的id号
$this->db->insert('goods',$data); $gid=$this->db->insert_id('goods'); return $gid;
- EasyUI 创建对话框
对话框是特殊的窗口,它能包括上面的工具栏和下面的按钮.默认对话框不能改变大小,但是用户可以设置resizeable属性为true来使它可以被改变大小:对话框非常简单,可以使用DIV标记创建: < ...
- 用 malloc 或 new 申请内存之后,应该立即检查指针值是否为 NULL
用 malloc 或 new 申请内存之后,应该立即检查指针值是否为 NULL. 防止使用指针值为 NULL 的内存. #include <iostream> #include <s ...
- Sencha Touch快速入门(译)
翻译自:http://www.sencha.com/learn/sencha-touch-quick-start/ 1.下载Sencha Touch SDK——下载链接 2.安装Safari或Chro ...
- GitHub Permission to <<repository>> denied to <<username>>
I kept receiving a 403 error saying my usual username couldn’t access the repository with my usual a ...
- wireshark: no interface can be used for capturing in this system
ubuntu14.04下使用wireshark找不到网卡... 解决方法: Open a terminal by pressing Ctrl+Alt+T and type the following ...
- 判断asp.net中session过期方法的比较
重写继承page的OnInit()虚方法,在需要的界面上,继承这个类. 1.新建继承page类的类JudgeSession,实现接口成员. 2.重写OnInit()方法,判断session情况. 3. ...
- MFC获取系统当前时间
1.使用CTime类 CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime(); str=tm.Format("现在时间是%Y年% ...