zoukankan      html  css  js  c++  java
  • 2020杭电HDU-6768多校第二场The Oculus(假斐波那契数列真Hash)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6768

    Problem Description

    Let's define the Fibonacci sequence (F_1,F_2,… as F_1=1,F_2=2,F_i=F_{i−1}+F_{i−2}) (i≥3).

    It's well known that every positive integer x has its unique Fibonacci representation $(b_1,b_2,…,b_n) $such that:

    · (b_1×F_1+b_2×F_2+⋯+b_n×F_n=x).

    · bn=1, and for each i (1≤i<n), bi∈{0,1} always holds.

    · For each i (1≤i<n), bi×bi+1=0 always holds.

    For example, 4=(1,0,1), 5=(0,0,0,1), and 20=(0,1,0,1,0,1) because (20=F_2+F_4+F_6=2+5+13).

    There are two positive integers A and B written in Fibonacci representation, Skywalkert calculated the product of A and B and written the result C in Fibonacci representation. Assume the Fibonacci representation of C is ((b_1,b_2,…,b_n)), Little Q then selected a bit k (1≤k<n) such that bk=1 and modified bk to 0.

    It is so slow for Skywalkert to calculate the correct result again using Fast Fourier Transform and tedious reduction. Please help Skywalkert to find which bit k was modified.

    Input
    The first line of the input contains a single integer T (1≤T≤10000), the number of test cases.

    For each case, the first line of the input contains the Fibonacci representation of A, the second line contains the Fibonacci representation of B, and the third line contains the Fibonacci representation of modified C.

    Each line starts with an integer n, denoting the length of the Fibonacci representation, followed by n integers (b_1,b_2,…,b_n), denoting the value of each bit.

    It is guaranteed that:

    · 1≤|A|,|B|≤1000000.

    · 2≤|C|≤|A|+|B|+1.

    ·∑|A|,∑|B|≤5000000.

    Output
    For each test case, output a single line containing an integer, the value of k.

    Sample Input
    1
    3 1 0 1
    4 0 0 0 1
    6 0 1 0 0 0 1

    Sample Output
    4

    题目大意:给你两个数,每个都是用斐波那契数列(01表示)来表示的,规定(F_1=1,F_2=2),再给你他们相乘后的结果C用斐波那契数列来表示,现在我将C中的斐波那契数列的某一位1删掉,问我删掉的是哪一位。
    比如说样例是(3 imes 5) 3可以用(f_1+0f_2+f_3)来表示,那么就是(101)了,5可以用(f_4)来表示,他们相乘的结果为20可以表示为(f_2+f_4+f_6),中间很明显丢失了第四位

    emmm,题目是真的假。。。看起来唬人的一批,好像还要跑NTT来着。。。结果一个Hash就过去了。。。我们直接暴力计算A和B的值,然后乘一下,跟C的值进行比较就可以了。不过在这之前我们要把斐波那契的Hash值预处理处理。

    以下是AC代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef unsigned long long ull;
    
    const int mac=1e6+10;
    
    ull dp[mac*2];
    int a[mac],b[mac],c[mac*2];
    
    int main(int argc, char const *argv[])
    {
    	int t;
    	dp[1]=1;dp[2]=2;
    	for (int i=3; i<mac*2; i++)
    		dp[i]=dp[i-1]+dp[i-2];
    	scanf ("%d",&t);
    	while (t--){
    		int na,nb,nc;
    		scanf ("%d",&na);
    		for (int i=1; i<=na; i++)
    			scanf ("%d",&a[i]);
    		scanf ("%d",&nb);
    		for (int i=1; i<=nb; i++)
    			scanf ("%d",&b[i]);
    		scanf ("%d",&nc);
    		for (int i=1; i<=nc; i++)
    			scanf ("%d",&c[i]);
    		ull s1=0,s2=0,s3=0;
    		for (int i=1; i<=na; i++)
    			if (a[i]) s1+=dp[i];
    		for (int i=1; i<=nb; i++)
    			if (b[i]) s2+=dp[i];
    		for (int i=1; i<=nc; i++)
    			if (c[i]) s3+=dp[i];
    		for (int i=1; i<=na+nb+1; i++){
    			if (s3+dp[i]==s1*s2){
    				printf("%d
    ",i);
    				break;
    			}
    		}
    	}
    	return 0;
    }
    
    路漫漫兮
  • 相关阅读:
    python 判断返回结果 in用法
    关于requests的session方法保持不了cookie的问题。(seesion的意思是保持一个会话,比如 登陆后继续操作(记录身份信息) 而requests是单次请求的请求,身份信息不会被记录)
    python-selenium并发执行测试用例(方法一 各模块每一条并发执行)
    python 正则表达提取方法 (提取不来的信息print不出来 加个输出type 再print信息即可)
    unittest框架 assertEqual 报错 让其出现中文的方法(这个问题出现时 我找了老半天) 还追加了 报错信息自定义的方法
    python 指定文件编码的方法
    解决python中路径中包含中文无法找到文件的问题
    python 字符转换记录
    python-selenium 并发执行用例的问题
    深度影响价值
  • 原文地址:https://www.cnblogs.com/lonely-wind-/p/13368292.html
Copyright © 2011-2022 走看看