想把两道题目一起写一下
就先说简单的1142
这道题目是 2017年度上学期第三次月赛的B题
1142: Real Small Water Problem
Time Limit: 1 Sec | Memory Limit: 128 MB | |
Submit: 37 | Solved: 10 |
Description
The senior wanted you to create a water problem.This made you a headache.So you asked BingYu for help.Immediately after he listened,he came up with a problem:
Give you a positive integer n.
Function F_x satisfies:
F(0) = sinn
F(x) = sinF(x-1) (x>0)
Calculate F(n).
Give you a positive integer n.
Function F_x satisfies:
F(0) = sinn
F(x) = sinF(x-1) (x>0)
Calculate F(n).
Input
The input contains no more than 20 test cases.
For each test case,the only line consists of one integer n.
0<=n<=100.
For each test case,the only line consists of one integer n.
0<=n<=100.
Output
For each given n,print the answer in a single line.The result should be rounded to six decimal places.
Sample Input
0
1
2
Sample Output
0.000000
0.745624
0.709700
HINT
sin函数在math.h头文件里。
例如算1的sin值
double ans=sin(1);
没啥好讲的感觉 直接上代码(真 • 水题)
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { double m,t; int a; while(~scanf("%d",&a)) { m=sin(a); for (int i=0;i<a;i++) m=sin(m); t=m; printf("%.6lf\n",t); } return 0; }
下面讲一下 1141
这题作为校赛热身赛的压轴题 看到题目的时候就有印象
是2017年度上学期第三次月赛的C题 当时没做出来 后来补题了
但是忘记数据如何处理了
想了很久才想出来...
1141: Real Big Water Problem
Time Limit: 1 Sec | Memory Limit: 128 MB | |
Submit: 65 | Solved: 20 |
Description
If you have solved the small water problem,let's see this big one.If you don't,I suggest you ignore this problem!
Also give you a positive integer n.
Function F_x satisfies:
F(0) = cos n
F(x) = cos F(x-1) (x>0)
Calculate F(n).
Input
The input contains no more than 20 test cases.
For each test case,the only line consists of one integer n.
0 <= n <= 10^30.
Output
For each given n,print the answer in a single line.The result should be rounded to six decimal places.
Sample Input
0
1
2
Sample Output
1.000000
0.857553
0.610065
HINT
cos函数在math.h头文件里。
例如:计算1的cos值:double ans=cos(1);
注意:这个题的数据范围
这题的数据特别大 用 long long 都存不下这么大的数据
所以考虑用 字符数组 读入 然后再用 atoi 函数将字符转化为数字
其次 打表看一下 数据是有规律的
从 n=35 开始 输出结果不变 恒为 0.739085
放一下代码:
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> #include <string.h> using namespace std; char a[105]; double x[105]; void f(int n) { x[0]=cos(n); for (int i=1; i<100; i++) x[i]=cos(x[i-1]); } int main() { int n; while (~scanf("%s",a))//10的30次方太大 用字符数组存 { memset(x,0,sizeof x); if (strlen(a)>=3) { printf("0.739085\n"); continue; } else if (strlen(a)<3) n=atoi(a);//将char转化成int if (n<40)//数据有规律 n>35时x[n]的大小不变 为定值 { f(n); printf("%lf\n",x[n]); } else printf("0.739085\n"); } return 0; }
注:sin() 和 cos()都在 math.h 的头文件里
数据太大存不了时 要考虑以别的形式存储数据