zoukankan      html  css  js  c++  java
  • ACM_出题人这样不好吧

    出题人这样不好吧

    Time Limit: 2000/1000ms (Java/Others)

    Problem Description:

    作为编协的第一次月赛,肯定是要有防AK(ALL KILL)的题目的,只会Fibnacci数的出题人绞尽脑汁,没能想出一道难题,没办法只好在题面上做一些手脚(加密)。
    其中有一道题题面是这样的:hjxhs ia dvwpude z,he sn f snrzad deppahe, tbcm wytj ir sm zvdpzdxiq uus tjc ta n dijphqer rclu taw yl p.
    比赛时,XX神对题面研究了两个多小时,终于找到一点点规律,破解出了前4个单词hjxhs ia dvwpude z,是given an integer n。但是比赛的时间已经不多了,XX神需要你的帮助。请帮他解密题面,并帮他ac了这个题。

    Input:

    输入包含多组数据(EOF)。对于每组数据,输入一个数字n(1<=n<=100000);

    Output:

    对于每组数据,输出答案。

    Sample Input:

    1

    Sample Output:

    1
    解题思路:找规律。对比一下原题前4个单词和解密的4个单词的ASCII值,可以得出关于斐波那契数列的对应关系,简单模拟一下即可得出规律。先算出:hjxhs ia dvwpude z和given an integer n的两个字符串中各字母ascil值减'a'后,进行对比可得:
    7 9 23 7 18 8 0 3 21 22 15 20 3 4 25  
    6 8 21 4 13 0 13 8 13 19 4 6 4 17 13
    1 1 2 3 5 8 13 21(3-21+26==8)....
    突破口是题干中“只会Fibnacci数的出题人”,刚好上面两行数字对应着减下来是:1 1 2 3 5 8 13…(计算斐波那契数列时要取余26)。
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     int fib[120]={1,1};
     5     for(int i=2;i<120;++i)
     6         fib[i]=(fib[i-1]+fib[i-2])%26;//取余26
     7     string str="hjxhs ia dvwpude z,he sn f snrzad deppahe, tbcm wytj ir sm zvdpzdxiq uus tjc ta n dijphqer rclu taw yl p.";
     8     for(size_t i=0,b=0;i<str.length()-1;++i){
     9         if(str[i]!=' '&&str[i]!=',')
    10             printf("%c",(str[i]-'a'-fib[b++]+26)%26+'a');
    11         else printf("%c",str[i]);
    12     }
    13     return 0;
    14 }
    因此,程序输出为:given an integer n,it is a simple problem, your task is to calculate the sum of n integers from one to n.即计算1~n所有数的总和。
    AC代码:
    1 #include<bits/stdc++.h>
    2 using namespace std;
    3 int main(){
    4     long long n;//避免数据溢出
    5     while(cin>>n){cout<<(1+n)*n/2<<endl;}
    6     return 0;
    7 }
  • 相关阅读:
    【修订】为什么OO方法是有本质缺陷的?
    jQuery到底有什么好?
    qsort还是std::sort,一个排序引发的血案
    小小的吹一下集结号~
    谈谈学习与讨论风格:信任、质疑与交流
    职场中的我们,应该有多和谐?
    我到底是在干嘛?
    最近一些想法
    老饭新炒:object based、object oriented与弱类语言
    Flash性能分析与调试工具
  • 原文地址:https://www.cnblogs.com/acgoto/p/9237557.html
Copyright © 2011-2022 走看看