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值,可以得出关于斐波那契数列的对应关系,简单模拟一下即可。
 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 }

猜你喜欢

转载自www.cnblogs.com/acgoto/p/9237557.html
今日推荐