「SHUPC 2024」 函数

题意

求题目中给出的函数值。

分析

Way 1

直接模拟,由于题目有 spj,所以可以用 c++ 自带函数算。虽然没有 \(\cot\) 函数,但是可以用 \(\frac{1}{\tan}\) 代替。

c++ 没有自带 \(\pi\),但是可以用 \(\arccos(-1)\) 表示。

Way 2

我们用画图软件画一下这个函数的图像。

炸了

看图可知,对于实数 \(x\)\(f(x)\) 其实就是 \(x\) 向下取整后的结果。好心的出题人为了不为难你,甚至还加入了 \(x\notin\mathbb{N}\) 的条件。

所以直接输出 floor(x) 就行了。

Code

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define dbg(x) cout<<#x<<": "<<x<<"\n"
inline ll read(){ll x=0,f=1;char c=getchar();while(c<48||c>57){if(c==45)f=0;c=getchar();}while(c>47&&c<58)x=(x<<3)+(x<<1)+(c^48),c=getchar();return f?x:-x;}
const ll mod=1e9+7,maxn=1e5+5;
#define pi acos(-1)
ll t;
inline double f(double x){
    return x-0.5+atan(1.0/tan(pi*x))/pi;
}
signed main(){
    t=read();
    while(t--){
        double x;
        cin>>x;
        printf("%lf\n",f(x));
    }
    return 0;
}
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define dbg(x) cout<<#x<<": "<<x<<"\n"
inline ll read(){ll x=0,f=1;char c=getchar();while(c<48||c>57){if(c==45)f=0;c=getchar();}while(c>47&&c<58)x=(x<<3)+(x<<1)+(c^48),c=getchar();return f?x:-x;}
const ll mod=1e9+7,maxn=1e5+5;
ll t;
signed main(){
    t=read();
    while(t--){
        double x;
        cin>>x;
        printf("%lf\n",floor(x));
    }
    return 0;
}
posted @ 2024-12-20 15:36  run-away  阅读(44)  评论(0)    收藏  举报