HDOJ 6768 The Oculus
http://acm.hdu.edu.cn/showproblem.php?pid=6768
题意:
一个正整数 表示为 斐波那契数列数列。
存在当前第i个斐波那契数 bi 为1,否则为0。
给三个斐波那契数列表示A B C,问A * B与C修改哪一位之后 的b值相等。
思路:
哈希 求模 再得差值
找到差值在哪一位
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include<deque> #include<iomanip> #include<list> #include<map> #include<queue> #include<set> #include<stack> #include<vector> #include <vector> #include <iterator> #include <utility> #include <sstream> #include <limits> #include <numeric> #include <functional> using namespace std; #define gc getchar() #define mem(a) memset(a,0,sizeof(a)) //#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef char ch; typedef double db; const double PI=acos(-1.0); const double eps=1e-6; const int inf=0x3f3f3f3f; const int maxn=1e5+10; const int maxm=100+10; const int N=2e5+10; const int mod=1e9+7; ll a[maxn] = {0}; ll b[maxn] = {0}; int n[maxn]; int main() { int T = 0; a[1] = 1; b[1] = 1; a[2] = 2; b[2] = 2; for(int i = 3;i<maxn;i++) { int value = 0; cin >> T; a[i] = (a[i-1] + a[i-2]) % mod; b[i] = (b[i-1] + b[i-2]) % mod; int p = 0; while(T--) { ll aa = 0 , aa1 = 0; ll bb = 0 , bb1 = 0; int k = 0; cin >> k; for(int j = 1;j<=k;j++) { cin >> value; if(value != 0) { aa += a[j]; aa %= mod; aa1 += b[j]; aa1 %= mod; } } cin >> k; value = 0; for(int j = 1;j<=k;j++) { cin >> value; if(value != 0) { bb += a[j]; bb %= mod; bb1 += b[j]; bb1 %= mod; } } ll res_1 = aa * bb % mod; ll res_2 = aa1 * bb1 % mod; cin >> k; ll add1 = 0; ll add2 = 0; for(int i = 1;i <= k;i++) { cin >> n[i]; if(n[i] != 0) { add1 = (add1 + a[i]) % mod; add2 = (add2 + b[i]) % mod; } } for(int i = 1;i<=k;i++) { if(n[i] == 0) { ll val1 = (add1 + a[i]) % mod; ll val2 = (add2 + b[i]) % mod; if(val1 == add1 && val2 == add2) { p = i; break; } } } cout << p; } return 0; }