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 ...
随机推荐
- mysql实现经纬度计算两个坐标之间的距离
DELIMITER $$CREATE DEFINER = CURRENT_USER FUNCTION `getDistance`(`lon1` float,`lat1` float,`lon2` fl ...
- 构造 - Codeforces Round #319 (Div. 1)C. Points on Plane
Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...
- EasyUI Window和Layout
我们建立tabs内容. <div class="easyui-window" title="Layout Window" icon="icon- ...
- javascript -- 阻止默认事件 阻止事件冒泡
1. event.preventDefault(); -- 阻止元素的默认事件.注:a元素的点击跳转的默认事件 , button,radio等表单元素的默认事件 , div 元素没有默认事件 例: ...
- 在MFC中改变控件的TAB顺序
在MFC界面中,控件的TAB顺序如果乱了,不合理,可能会使界面出现意料之外的显示. 例如,在用Spin Control来对Edit Control内的值进行增减时,如果Edit Control.Spi ...
- 【NLP+Deep learning】好文
http://blog.jobbole.com/77709/ 原文出处: http://colah.github.io/posts/2014-07-NLP-RNNs-Representations/
- HTML5游戏制作完全指南
简介 创建画布 游戏循环 Hello world 创建player 键盘控制 a:使用jQuery Hotkeys b:移动player 添加更多游戏元素 炮弹 敌人 使用图片 碰撞检测 声音 简介 ...
- 【BZOJ2973】石头游戏 矩阵乘法
[BZOJ2973]石头游戏 Description 石头游戏的规则是这样的. 石头游戏在一个n行m列的方格阵上进行.每个格子对应了一个编号在0~9之间的操作序列. 操作序列是一个长度不超过6且循环执 ...
- 理解CSS3 isolation: isolate的表现和作用
转自:http://www.zhangxinxu.com/wordpress/?p=5155 只要元素可以创建层叠上下文,就可以阻断mix-blend-mode! 于是,不仅仅是isolation:i ...
- Chrome浏览器断点调试无效的问题
问题是这样的,在使用chrome浏览器调试JavaScript的时候,突然设置的断点失效了,怎么弄都没有效果. 折腾了半天,尝试了各种方法就是没有用. 解决:重启一下chrome浏览器就好了,这似乎是 ...