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 ...
随机推荐
- C++ 运算符重载三(链式编程)
//运算符重载之链式编程 #include<iostream> using namespace std; //对于友元函数重载运算符只适用于左操作数是系统变量的场景 //因为成员无法在系统 ...
- VMware ESXi vsan.v00卡 停
重装VMware ESXi 6.5,结果在loading vsan.v00文件的时候卡住了,过了几个小时都停留在这个界面.无意间重启使用UEFI 启动,提示某文件校验出错,MD5对不上,重新写入安装镜 ...
- hdu 2019:数列有序!(数据结构,直接插入排序+折半插入排序)
数列有序! Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submiss ...
- 修改Android 界面颜色
btnGetCode.setTextColor(getResources().getColor(R.color.dark_white)); Color.parseColor("#1a71d4 ...
- AWS CLI 【S3】
1.创建一个桶&删除一个桶 root@syavingc:~# aws s3 mb s3://syavingc #创建一个桶 make_bucket: syavingc root@syaving ...
- ASP.NET MVC5 新特性:Attribute路由使用详解
1.什么是Attribute路由?怎么样启用Attribute路由? 微软在 ASP.NET MVC5 中引入了一种新型路由:Attribute路由,顾名思义,Attribute路由是通过Attrib ...
- Intent讲解
什么是Intent? Intent是一个消息传递对象,可以使用它来启动其它应用组件.Intent使组件之间通信更加便利,主要用于以下三点: 启动Activity: 可以将intent作为参数调用Con ...
- Django学习笔记第八篇--实战练习四--为你的视图函数自定义装饰器
零.背景: 对于登录后面所有视图函数,都需要验证登录信息,一般而言就是验证cookie里面的一些信息.所以你可以这么写函数: def personinfo(request): ": retu ...
- 【黑金原创教程】【TimeQuest】【第四章】内部延迟与其他
声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...
- Objective-C内存管理基础
2011-05-11 15:45 朱祁林 http://zhuqil.cnblogs.com 字号:T | T 本文我们将介绍<Objective-C内存管理基础>,在iOS开发中,内存管 ...