题解归档 - cf104118A

题解归档 - cf104118A

本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。

思路

cf104118A - An Easy Calculus Question

The full statement is in contests/104118/statements.pdf because the HTML page only contains samples.

Use the constants given by the statement hint:

  • a=-2, b=1, c=-14, d=17.

Then evaluate the piecewise function:

  • x <= -3: -(x+4)^2+8
  • -3 < x <= 2: -2x+1
  • x > 2: x^3-14x+17

Input x is an integer in [-10,10], and the answer is always integer.

代码

来源:problems/cf104118A/solution.cpp

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll x;
    cin>>x;
    ll ans;
    if(x<=-3) ans=-(x+4)*(x+4)+8;
    else if(x<=2) ans=-2*x+1;
    else ans=x*x*x-14*x+17;
    cout<<ans<<"\n";
    return 0;
}
~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:题解归档 - cf104118A
文章链接:https://www.fangshaonian.cn/archives/166/
最后编辑:2026 年 6 月 28 日 19:03 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 3 + 6 =
快来做第一个评论的人吧~