ACdream 1069 无耻的出题人 无聊写着玩的题

题目大意:

现在题目被加密了, 给出加密后的串

hjxh dwh v vxxpde,mmo ijzr yfcz hg pbzrxdvgqij rid stl mc zspm vfvuu vb uwu spmwzh.

一直前面4个词是give you a number, 出题人说自己只会Fibonacci...

解密这一段文字然后写程序


大致思路:

既然出题人说自己只会Fibonacci, 脑洞一下这个提议, 注意到前几个字母: (h, g), (j, i), (x, v)..差距依次是1, 1, 2, 3, 5, 8....于是猜想字符差距是Fibonacci数, 以26为循环节即可

得到解密之后的题面是:give you a number,and your task is calculating the sum of each digit in the number

于是就是个无聊的求按位之和的题了, 注意n是long long 范围当n取-2^63的时候转正整数的long long会出错就行了


代码如下:

Result  :  Accepted     Memory  :  1672 KB     Time  :  0 ms

/*
* this code is made by Gatevin
* Problem: 1069
* Verdict: Accepted
* Submission Date: 2015-09-13 22:10:16
* Time: 0MS
* Memory: 1672KB
*/
/*
 * Author: Gatevin
 * Created Time:  2015/9/12 12:12:47
 * File Name: Sakura_Chiyo.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
typedef unsigned long long ulint;
 
/*
 * hjxh dwh v vxxpde,mmo ijzr yfcz hg pbzrxdvgqij rid stl mc zspm vfvuu vb uwu spmwzh
 * give you a number
 * h - g = 1
 * j - i = 1
 * x - v = 2
 * h - e = 3
 * d - y = 26 + d - y = 5
 * w - o = 8
 * 猜想, 解密需要将所有字符加上Fibonacci数取模26得到, 前两项是1 1
 */
 
int fib[100];
 
int main()
{
    //freopen("out.out", "w", stdout);
    fib[0] = fib[1] = 1;
    string s = "hjxh dwh v vxxpde,mmo ijzr yfcz hg pbzrxdvgqij rid stl mc zspm vfvuu vb uwu spmwzh";
    for(int i = 2, sz = s.length(); i < sz; i++)
        fib[i] = (fib[i - 1] + fib[i - 2]) % 26;
    int num = 0;
    for(int i = 0, sz = s.length(); i < sz; i++)
        if(s[i] != ' ' && s[i] != ',') s[i] = ((s[i] - 'a') - fib[num++] + 26) % 26 + 'a';
    //cout<<s<<endl;
    //s = "give you a number,and your task is calculating the sum of each digit in the number";
    lint n;
    while(scanf("%lld", &n) != EOF)
    {
        ulint N;
        if(n < 0)
        {
            N = (ulint)(-(n + 1)) + 1uLL;
        }
        else N = n;
        ulint ans = 0;
        while(N)
        {
            ans += N % 10uLL;
            N /= 10uLL;
        }
         
        printf("%llu\n", ans);
    }
    return 0;
}



你可能感兴趣的:(1069,ACdream,无耻的出题人)