Rikka with Time Complexity

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 448    Accepted Submission(s): 159

Problem Description
Calculating and comparing time complexity for algorithms are the most important necessary skills for CS students.

This semester, Rikka applies for the assistant of course "Algorithm Analysis". Now Rikka needs to set problems for the final examination, and she is going to set some tasks about time complexity.

Let fa(n)=log…logn (there are exactly a log in this function, and log uses base 2). And then, for an integer array A, Rikka defines gA(n) in the following way (B is the suffix of A with length |A|−1):

gA(n)={fA1(n)fA1(n)gB(n)|A|=1|A|>1

For example, g[1,2](n)=(logn)loglogn and g[3,1,1](n)=(logloglogn)(logn)logn.

Now, given integer arrays A and B, Rikka wants you to compare gA(n) with gB(n). i.e., let k be limn→+∞gA(n)gB(n). If k=0, output −1; if k=+∞, output 1; otherwise output 0.

 
Input
The first line contains a single number t(1≤t≤105), the number of testcases.

For each testcase, the first line contains two integers a,b(1≤a,b≤3), the length of A and B.

The second line contains a integers Ai and the third line contains b integers Bi(1≤Ai,Bi≤109), which describe A and B.

 
Output
For each testcase, output a single line with a single integer, the answer.
 
Sample Input
3
1 1
1
2
2 2
1 2
2 1
1 3
1
1000000000 3 3
 
Sample Output
1
-1
-1
题意:定义 f(a) = loglog...log(n) (有a个log),g(A) = f(a1)^f(a2)^f(a3),求lim(n->+∞)g(A)/g(B)
分析:
  考虑A数组最多有三个数,所以对g(A)取两次log
  即:loglog(f(a1)^f(a2)^f(a3)) = log(f(a2)^f(a3)*log(f(a1)) = log(f(a2)^f(a3)) + loglog(f(a1)) = f(a3)*log(f(a2) + loglog(f(a1)) = f(a3)*f(a2+1) + f(a1+2)
  将上式去掉log和极限后可化为:a3*(a2+1)+(a1+2)*inf(因为n->+∞,去掉log后(a1+2)还要乘上一个inf,(log)inf n n->inf等于1)
  注意a1,a2,a3越大,f(a1),f(a2),f(a3)的值越小,所以去掉log后上下式子比较大小得到的结果是相反的
  即:lim(n->+∞)g(A)/g(B) = lim(n->+∞)((a3*(a2+1)+(a1+2)*inf)/(b3*(b2+1)+(b1+2)*inf))
  求极限也就是比较上下两个式子的大小,如果上面大于下面,实际是上面小于下面(没去log实际的值),则结果是趋向于0,输出-1
  类似,上面小于下面,输出1,上面等于下面,输出0
  接下来看怎么比较a3*(a2+1)+(a1+2)*inf和b3*(b2+1)+(b1+2)*inf
  注意这个比较是建立在log上的,所以我们应该先找出较小的一对数,两对数:(a3,a2+1),(a1+2,inf)
  我们先排序好每对数,每对数里再排序好两个数,然后直接遍历比较大小
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const double eps = 1e-8;
const ll mod = 998244353;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
void getmin(ll *a) {
if( min(a[0],a[1]) == min(a[2],a[3]) ) {
if( max(a[0],a[1]) >= max(a[2],a[3]) ) {
swap(a[0],a[2]), swap(a[1],a[3]);
}
} else if( min(a[0],a[1]) > min(a[2],a[3]) ) {
swap(a[0],a[2]), swap(a[1],a[3]);
}
if( a[0] > a[1] ) {
swap(a[0],a[1]);
}
if( a[2] > a[3] ) {
swap(a[2],a[3]);
}
}
int main() {
ios::sync_with_stdio(0);
ll T;
cin >> T;
while( T -- ) {
ll a, b, A[4] = {0}, B[4] = {0};
cin >> a >> b;
for( ll i = 1; i <= a; i ++ ) {
cin >> A[i];
}
for( ll i = 1; i <= b; i ++ ) {
cin >> B[i];
}
A[0] = inf, B[0] = inf;
for( ll i = 1; i <= 3; i ++ ) {
if(A[i]) {
A[i] += 3-i;
} else {
A[i] = inf;
}
if(B[i]) {
B[i] += 3-i;
} else {
B[i] = inf;
}
}
getmin(A),getmin(B);
ll ans = 0;
for( ll i = 0; i <= 3; i ++ ) {
if( A[i] == B[i] ) {
continue;
}
if( A[i] < B[i] ) {
ans = 1;
break;
} else if( A[i] > B[i] ) {
ans = -1;
break;
}
}
cout << ans << endl;
}
return 0;
}

  

杭电多校第九场 hdu6424 Rikka with Time Complexity 数学的更多相关文章

  1. 杭电多校第九场 hdu6425 Rikka with Badminton 组合数学 思维

    Rikka with Badminton Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/O ...

  2. 杭电多校第九场 HDU6415 Rikka with Nash Equilibrium dp

    Rikka with Nash Equilibrium Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K ...

  3. 杭电多校第九场 D Rikka with Stone-Paper-Scissors 数学

    Rikka with Stone-Paper-Scissors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/52428 ...

  4. 2018 Multi-University Training Contest 9 杭电多校第九场 (有坑待补)

    咕咕咕了太久  多校博客直接从第三场跳到了第九场orz 见谅见谅(会补的!) 明明最后看下来是dp场 但是硬生生被我们做成了组合数专场…… 听说jls把我们用组合数做的题都用dp来了遍 这里只放了用组 ...

  5. Rikka with Game[技巧]----2019 杭电多校第九场:1005

      Rikka with Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Othe ...

  6. Rikka with Travels(2019年杭电多校第九场07题+HDU6686+树形dp)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 定义\(L(a,b)\)为结点\(a\)到结点\(b\)的路径上的结点数,问有种\(pair(L(a,b),L(c,d))\)取值,其中结点\ ...

  7. 2019杭电多校第⑨场B Rikka with Cake (主席树,离散化)

    题意: 给定一块n*m的矩形区域,在区域内有若干点,每个顶点发出一条射线,有上下左右四个方向,问矩形被分成了几个区域? 思路: 稍加观察和枚举可以发现,区域数量=射线交点数+1(可以用欧拉定理验证,但 ...

  8. 2018 Multi-University Training Contest 1 杭电多校第一场

    抱着可能杭电的多校1比牛客的多校1更恐怖的想法 看到三道签到题 幸福的都快哭出来了好吗 1001  Maximum Multiple(hdoj 6298) 链接:http://acm.hdu.edu. ...

  9. 2018 Multi-University Training Contest 2 杭电多校第二场

    开始逐渐习惯被多校虐orz  菜是原罪 1004  Game    (hdoj 6312) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6312 虽然披着 ...

随机推荐

  1. Java1.8新特性实战

    public class JDK8_features {private ArrayList<Integer> list; @Testpublic void test(){/*** 1.La ...

  2. Extjs的使用总结笔记

    一:Extjs自带验证 1.alpha //只能输入字母,无法输入其他(如数字,特殊符号等) 2.alphanum//只能输入字母和数字,无法输入其他 3.email//email验证,要求的格式是& ...

  3. sql server 2008 外键的级联操作

    问题提出:现在我有三张表,学生Student,课程Course,成绩SC 1.  学生表Student,主键是学号Sno 2.  课程Course,主码是课程号Cno 3.  成绩SC,主码是Sno和 ...

  4. 解决报错:类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用

    Razor视图引擎中,使用部分视图编译报错 类型“System.Object”在未被引用的程序集中定义.必须添加对程序集“System.Runtime, Version=4.0.0.0, Cultur ...

  5. 比特平面分层(一些基本的灰度变换函数)基本原理及Python实现

    1. 基本原理 在灰度图中,像素值的范围为[0, 255],即共有256级灰度.在计算机中,我们使用8比特数来表示每一个像素值.因此可以提取出不同比特层面的灰度图.比特层面分层可用于图片压缩:只储存较 ...

  6. kafka消息的处理机制(五)

    这一篇我们不在是探讨kafka的使用,前面几篇基本讲解了工作中的使用方式,基本api的使用还需要更深入的去钻研,多使用才会有提高.今天主要是探讨一下kafka的消息复制以及消息处理机制. 1. bro ...

  7. git基本命令学习(一)

    1 git配置文件 1.1 git权限控制 git有三个不同的权限控制文件,高优先权的设置会覆盖低优先权的设置项,以下按照优先权从高到低介绍: 文件夹中".git" 子文件夹中的c ...

  8. 解决 Android 中出现依赖多个版本支持库的问题

    在 app 的 build.gradle 中引入依赖时发现如下错误: All com.android.support libraries must use the exact same version ...

  9. Spring入门(九):运行时值注入

    Spring提供了2种方式在运行时注入值: 属性占位符(Property placeholder) Spring表达式语言(SpEL) 1. 属性占位符 1.1 注入外部的值 1.1.1 使用Envi ...

  10. sql server 怎么查看blocked的线程

    select spid ,blocked from master..sysprocesses