GTY's math problem

Time Limit: 1000/1000 MS
(Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description

GTY is a GodBull who will get an Au in
NOI . To have more time to learn algorithm knowledge, he never does his math
homework. His math teacher is very unhappy for that, but she can't do anything
because GTY can always get a good mark in math exams. One day, the math teacher
asked GTY to answer a question. There are four numbers on the blackboard - a,b,c,d. The math teacher wants GTY to compare ab with cd. Because GTY never does his homework,
he can't figure out this problem! If GTY can't answer this question correctly,
he will have to do his homework. So help him!

Input

Multi test cases (about 5000). Every
case contains four integers a,b,c,d(1≤a,b,c,d≤1000)separated by spaces. Please process to
the end of file.

Output

For each case , if ab>cd , print '>'. if ab<cd , print '<'. if ab=cd , print '='.

Sample Input

2 1 1 2

2 4 4 2

10 10 9 11

Sample Output

>

=

<

GTY's math problem

Time Limit: 1000/1000 MS
(Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1636    Accepted Submission(s): 298

问题描述

众所周知,GTY是一位神犇,为了更好的虐场,他从来不写数学作业而是去屠题,他的数学老师非常不爽,但由于GTY每次考试都AK,她也不能说什么,有一天老师在黑板上写了四个数——a,b,c,d 然后让GTY比较abcd的大小,由于GTY不屑于虐这道题,就把这个问题交给你了。

输入描述

多组数据(约5000组),每组数据包含4个整数a,b,c,d(1≤a,b,c,d≤1000),用空格隔开

输出描述

对于每组数据,若ab>cd,输出”>”, 若ab<cd,输出”<”, 若ab=cd,输出”=”

输入样例

2 1 1 2

2 4 4 2

10 10 9 11

输出样例

>

=

<

思路  log(a^b)=b∗log(a)  注意精度!

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
#define emp (1e-8)
int main()
{
double a,b,c,d;
while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d)!=EOF)
{
if(fabs(b*log(a)-d*log(c))<=emp)
printf("=\n");
else if(b*log(a)>d*log(c))
printf(">\n");
else if(b*log(a)<d*log(c))
printf("<\n");
}
return ;
}

GTY's birthday gift

Time Limit: 2000/1000 MS
(Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description

FFZ's birthday is coming. GTY wants to
give a gift to ZZF. He asked his gay friends what he should give to ZZF. One of
them said, 'Nothing is more interesting than a number multiset.' So GTY decided
to make a multiset for ZZF. Multiset can contain elements with same values.
Because GTY wants to finish the gift as soon as possible, he will use JURUO
magic. It allows him to choose two numbers a and b(a,bS), and add a+b to the multiset. GTY can use the magic
for k times, and he wants the sum of the multiset is maximum, because the
larger the sum is, the happier FFZ will be. You need to help him calculate the
maximum sum of the multiset.

Input

Multi test cases (about 3) . The first
line contains two integers n and k (2≤n≤100000,1≤k≤1000000000). The second line contains n elements ai (1≤ai≤100000)separated by spaces , indicating the
multiset S .

Output

For each case , print the maximum sum of
the multiset (mod 10000007).

Sample Input

3 2

3 6 2

Sample Output

35

GTY's birthday gift

Time Limit: 2000/1000 MS
(Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 585    Accepted Submission(s): 103

问题描述

GTY的朋友ZZF的生日要来了,GTY问他的基友送什么礼物比较好,他的一个基友说送一个可重集吧!于是GTY找到了一个可重集S,GTY能使用神犇魔法k次,每次可以向可重集中加入一个数 a+b(a,bS),现在GTY想最大化可重集的和,这个工作就交给你了。

注:可重集是指可以包含多个相同元素的集合

输入描述

多组数据(约3组),每组数据的第一行有两个数n,k(2≤n≤100000,1≤k≤1000000000) 表示初始元素数量和可使用的魔法数,第二行包含n个数a(1≤ai≤100000)表示初始时可重集的元素

输出描述

对于每组数据,模10000007输出可重集可能的最大和。

输入样例

3 2

3 6 2

输出样例

35

这题是典型的矩阵快速幂:

这是公式:

#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL __int64
#define mod 10000007 int N; struct matrix
{
LL m[][];
};
int a[]; matrix multiply(matrix x,matrix y)
{
matrix temp;
memset(temp.m,,sizeof(temp.m));
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
if(x.m[i][j]==) continue;
for(int k=; k<; k++)
{
if(y.m[j][k]==) continue;
temp.m[i][k]+=x.m[i][j]*y.m[j][k]%mod;
temp.m[i][k]%=mod;
}
}
}
return temp;
} matrix quickmod(matrix a,int n)
{
matrix res;//单位阵
memset(res.m,,sizeof(res.m));
for(int i=;i<;i++) res.m[i][i]=;
while(n)
{
if(n&)
res=multiply(res,a);
n>>=;
a=multiply(a,a);
}
/* for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
printf("%8d",res.m[i][j]);
printf("\n");
}
printf("\n");*/
return res;
}
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
LL sum=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sort(a,a+n);
matrix ans;
ans.m[][]=;ans.m[][]=;ans.m[][]=;
ans.m[][]=;ans.m[][]=;ans.m[][]=;
ans.m[][]=;ans.m[][]=;ans.m[][]=;
ans=quickmod(ans,k); printf("%d\n",(ans.m[][]*sum+ans.m[][]*a[n-]+ans.m[][]*a[n-])%mod);
}
return ;
}

今天忘记报名BC了,只能现在做了。才做了2题!还要加油啊。

矩阵快速幂,还得谢谢庆神当初的传授啊。。。。哈哈!

BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)的更多相关文章

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

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

  2. 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库中有关的对数函数返回的都是浮点数,所以这又要涉 ...

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

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

  4. BestCoder Round #29 1003 (hdu 5172) GTY's gay friends [线段树 判不同 预处理 好题]

    传送门 GTY's gay friends Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  5. BestCoder Round #29 GTY's gay friends

    #include <cstdio> #include <cstring> #include <vector> #include <algorithm> ...

  6. HDU 5170 GTY's math problem 水题

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5170 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  7. HDU 5170 GTY's math problem

    数学题,a的b次方和c的d次方都很大,直接判断是做不出来的. 如果我们能找到一个函数F(x)是单调的,而F(X)的值又比较好算,那么可以通过比较F(X)的大小来判断自变量的大小. 令F(X)=log( ...

  8. hdu 5170 GTY's math problem(水,,数学,,)

    题意: 给a,b,c,d. 比较a^b和c^d的大小 思路: 比较log(a^b)和log(c^d)的大小 代码: int a,b,c,d; int main(){ while(scanf(" ...

  9. BestCoder Round #70 Jam's math problem(hdu 5615)

    Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...

随机推荐

  1. .net图表之ECharts随笔04-散点图

    见图说话,修改参数option实现上图显示: 1. 共用参数title还有一个属性subtext,可以用来设置副标题 2. tooltip与toolbox也是共用属性 3. dataZoom是设置滚动 ...

  2. web开发常用网络优化

    优化方法: 1.合并资源文件,减少HTTP请求 2.压缩资源文件减少请求大小 3.利用缓存机制,尽可能使用缓存减少请求 如何做前端路由 html5 api中的history能够让我们控制url跳转之后 ...

  3. 抓取分析网页批量下载评书(3)之批量下载mp3

         本系列目录:    <1.搜索有声小说>    <2.分析详细页地址>     <3.批量下载mp3>      本篇是大结局,看过前两篇的放心吧,不会有 ...

  4. [Vuejs] 组件 v-if 和 v-show 切换时生命周期钩子的执行

    v-if 初始渲染 初始值为 false 组件不会渲染,生命周期钩子不会执行,v-if 的渲染是惰性的. 初始值为 true 时,组件会进行渲染,并依次执行 beforeCreate,created, ...

  5. 一步步Cobol 400 上手自学入门教程03 - 数据部

    数据部的作用 程序中涉及到的全部数据(输入.输出.中间)都要在此定义,对它们的属性进行说明.主要描述以下属性: 数据类型(数值/字符)和存储形式(长度) 数据项之间的关系(层次和层号) 文件与记录的关 ...

  6. Python小白学习之路(二十五)—【装饰器的应用】

    通过一个任务来加深对装饰器的理解和应用 回顾:装饰器的框架 def timmer(func): def wrapper(): func() return wrapper 任务:给以下正在运行的程序加一 ...

  7. iOS-IAP内购的那些事(iOS内购漏单的问题)

    前言 说起内购,其实挺令开发者厌烦的,原因呢,先不说漏单的问题,首先苹果要扣除30%的销售额哦,可恨不?(我觉得可恨),有些想办法先隐藏掉第三方支付(支付宝.微信等),等项目上线了,再跳过内购使用第三 ...

  8. 理解WSGI

    WSGI是什么? WSGI,全称 Web Server Gateway Interface,或者 Python Web Server Gateway Interface ,是为 Python 语言定义 ...

  9. 从用户浏览器输入url到用户看到页面结果的过程,发生了什么事情?

    1.域名解析 域名解析的过程:  1).查询浏览器自身DNS缓存 2).若上面没有查找到,则搜索操作系统自身的dns缓存 3).若上面没有找到,则尝试读取hosts文件 4).若上面没有找到,向本地配 ...

  10. crontab命令使用文档.txt

    基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...