gdufe acm 1138 出题人这样不好吧

来源:互联网 发布:中国海关统计数据库 编辑:程序博客网 时间:2024/04/30 09:55

链接:http://acm.gdufe.edu.cn/Problem/read/id/1138
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

先算出:
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

突破口是题干中“只会Fibnacci数的出题人”,
刚好上面两行数字对应着减下来是:
1 1 2 3 5 8 13…

解密后其实就是:“given an integer n,it is a simple problem, your task is to calculate the sum of n integers from one to n.”
(算斐波那契数列时要取余26)

AC代码其实就几行:

#include <cstdio>int main(){    int n;    while(scanf("%d", &n) == 1){        long long ans = 1LL*(1 + n)*n/2;        printf("%lld\n", ans);    }    return 0;}
0 0
原创粉丝点击