【FOJ2206 11月月赛B】【观察找规律】函数求解 分析函数求值
来源:互联网 发布:比特彗星监听端口 编辑:程序博客网 时间:2024/06/10 14:58
Problem 2206 函数求解
Accept: 28 Submit: 46
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
给出n,求f(n)。
Input
第一行一个正整数T,表示数据组数。 接下来T行,每行一个正整数n。 T<=20,n<=2015000000。
Output
对于每组数据,输出一行f(n)。
Sample Input
2120150001
Sample Output
201520152014
Source
FOJ有奖月赛-2015年11月#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;int casenum,casei;const int V=20150001;int n,ans;int f(int x){if(x<V)return x+2014;else return f(f(x-2015));}int main(){scanf("%d",&casenum);for(casei=1;casei<=casenum;casei++){scanf("%d",&n);//printf("%d\n",f(n));if(n<V)ans=n+2014;else ans=20152014;printf("%d\n",ans);}return 0;}/*【题意】给你一个函数f()有f[n]=n+2014,n<20150001,f( f(n-2015) ),n>=20150001。每次给你一个n,(1<=n<=2015000000),让你输出f(n)。【类型】暴力找规律观察分析结论【分析】这道题,一开始想起来感觉有些懵,然后怕耽误时间,于是我干脆直接把对f()的定义写成了函数,然后就找到规律AC掉了,规律是这样的——if(n<V)ans=n+2014;else ans=20152014;为什么呢?设V=20150001;首先,n<V时ans=n+2014很好理解。然后,n>=V时,我们的值会变为f(f(x-2015))的结果。当x-2015>=V时,迭代会继续下去当x-2015<V时,相当于先减2015再加2014,即变成--x;这样我们会一直操作,直到x=20150001,然后答案会变成f(20150000)于是最后的答案会锁定在20152014*/
1 0
- 【FOJ2206 11月月赛B】【观察找规律】函数求解 分析函数求值
- 函数求值一<找规律>
- FZU 2206 函数求解(找规律)
- FZU 2206 函数求解 找规律
- 【找规律】【ZJOI2009】函数
- Fzu 2206 函数求解【规律】
- poj 3090 (欧拉函数,找规律)
- Hdu2177-博弈(Sg函数找规律)
- 找规律 B
- 函数求值
- 函数求值!
- 函数求值
- Codeforces 608B 找规律
- CodeForces 618B (找规律)
- FOJ有奖月赛-2015年11月 Problem B 函数求解
- FOJ有奖月赛-2015年11月-Problem B 函数求解
- FOJ有奖月赛-2015年11月 Problem B 函数求解
- FOJ有奖月赛-2015年11月 Problem B 函数求解
- hdu5563 ( Clarke and five-pointed star )
- 排序算法JAVA实现三
- 对js中的引用类型的理解(2)——Object类型
- SimpleDateFormat在jdk1.6与jdk1.7之间的差别
- linux设备树中pinctrl的配置(下)
- 【FOJ2206 11月月赛B】【观察找规律】函数求解 分析函数求值
- 文档的吐槽
- C++ 在函数中用static定义的变量的
- FastDFS的配置、部署与API使用解读(7)Nginx的FastDFS模块
- GBDT(MART) 迭代决策树入门教程 | 简介
- NDK编译OpenCV-3.0.0的配置文件
- 对js中的引用类型的理解(3)——Array类型
- NSString
- 人脸识别技术大总结(1)——Face Detection & Alignment