2117 : 我已经在路上了

时间限制:1 Sec 内存限制:256 MiB
提交:39 答案正确:8

提交 状态 编辑 讨论区

题目描述

spring是不折不扣的学霸,那可是机房考研中的头号选手,不吹不黑,spring出征,寸草不生

但是这个学霸从来不屑于写简单的东西,因为时间是可贵的,spring喜欢留给B站小姐姐。所以在计算数学求导的时候spring就想出来用编程来完成,这样岂不是美滋滋,正好符合spring高大上的气质

那么问题来了,基础的求导公式那么多,spring只是添加了少许几个原函数,分别为y=C,y=x,y=x^n,y=sinx,y=cosx,y=lnx,y=loga(x),y=e^x,,每次对一个原函数求导,但是学霸spring又觉得这样太简单,所以就决定可以在求导函数中加上常数(正整数,int范围),当然为了平衡难度,常数只能够在x前面,或者函数最前面这两个地方添加(如果两者为同一地点只能添加一次)。

输入

输入形式严格按照上面的函数形式,并且符合常规数学知识,其中C,n,a都是正整数的形式给出,均在int范围。

输出

输出按照样例实现,(拒绝杠精,不接受反驳)不用带有y'=,直接写出求导的结果,占一行。

样例输入

复制
y=sin5x
y=e^2x
y=2log13(8x)

样例输出

复制
5cos5x
2e^2x
2/ln13/x

注意:

      1、严格分类讨论,共八种情况;可以使用string的find()函数来找到每种情况的特殊字符段,该函数自行百度参数及使用方法。

      2、每种情况,注意拆分出常数项和x的系数项,用一个函数来实现这个反复的问题。

      3、每种情况,每个细节都要考虑到,常数项为“1”是否删去,x的系数项为“1”是否删除,理清思路后也就16种情况。具体自己列下来,整理清楚。

      4、特殊情况,y=x求导结果为1,y=1x^1等等18中特例!自行耐心构造!

      5、不全面的样例:

 y=sinx
y=sin200000x
y=100000sin200000x
y=2sinx y=cosx y=2000000cosx y=cos200000x
y=200000cos200000x y=lnx y=ln100000x y=1000000lnx y=100000ln100000x y=2log13(8x) y=200000log130000(10000x)
//特例需要约分,还需要注意系数a和n为1的地方
y=6ln6x y=ln6x
y=100000e^20000x y=10000000x y=1x y=x^ y=1x^ y=e^x y=10e^10x y=1x^1
y=123456789x^100000

建议AC后再看看题解:

    

 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#define ll long long
using namespace std;
#define N 100
ll get(char s[],ll beg){ //从下标beg的地方开始累乘出一个数值,不越界,找到不是数字的地方停下来
ll x=;
for(ll i=beg;i<(ll)strlen(s)&&s[i]>=''&&s[i]<='';i++){
x=x*+s[i]-'';
}
return x;
}
int main(){
char s[]; while(scanf("%*2s%s",s)!=EOF){ //在读取的时候跳过前两个字符(%*2c也阔以)
string st(s);
ll c,a,n,b; if(st.find("x^")!=-){ //cx^n求导-->(c*n)x^(n-1)
if(s[]>=''&&s[]<='')
c=get(s,);
else
c=;
ll x=st.find("^");
n=get(s,x+); if(c*n!=)printf("%lld",c*n);
cout<<"x";
if(n-==)printf("\n");
else printf("^%lld\n",n-);
} else if(st.find("sin")!=-){ //Csin(ax)求导
if(st[]>=''&&st[]<='')
c=get(s,);
else
c=;
ll x=st.find("n");
if(st[x+]=='x')
a=;
else
a=get(s,x+);
if(c*a!=)printf("%lld",c*a);
if(a==)
printf("%s%s\n","cos","x");
else
printf("%s%lld%s\n","cos",a,"x");
}
else if(st.find("cos")!=-){ //Ccos(ax)求导
if(st[]>=''&&st[]<='')
c=get(s,);
else
c=;
ll x=st.find("s");
if(st[x+]=='x')
a=;
else
a=get(s,x+); if(c*a==)
printf("-");
else
printf("-%lld",c*a);
if(a!=)
printf("%s%lld%s\n","sin",a,"x");
else
printf("%s\n","sinx"); }
else if(st.find("ln")!=-){ //cln(ax)求导 ==c/x
if(st[]>=''&&st[]<='')
c=get(s,);
else
c=;
ll x=st.find("n");
if(st[x+]=='x')
a=;
else
a=get(s,x+);
printf("%lld/",c); printf("x\n");
}
else if(st.find("log")!=-){ //nloga(bx)求导-->n/lna/x
if(st[]>=''&&st[]<='')
n=get(s,);
else
n=;
ll x=st.find("g");
a=get(s,x+);
x=st.find("(");
if(st[x+]=='x')
b=;
else
b=get(s,x+); printf("%lld/ln%lld/x\n",n,a);
}
else if(st.find("e^")!=-){ //y=ne^ax求导
if(st[]>=''&&st[]<='')
n=get(s,);
else
n=;
ll x=st.find("^");
if(st[x+]=='x')a=;
else
a=get(s,x+); if(a*n==)
printf("%s\n",s);
else{
printf("%llde^",a*n);
if(a==)
printf("x\n");
else
printf("%lldx\n",a);
}
}
else if(st.find("x")!=-){ //y=ax求导
if(st[]=='x')
printf("1\n");
else
printf("%lld\n",get(s,));
}
else
printf("0\n");
} return ;
}

(有注释,不懂留言即可)

zznu-oj-2117 : 我已经在路上了(求函数的原函数的字符串)--【暴力模拟题,花式模拟题,String大法好】的更多相关文章

  1. ZZNU - OJ - 2080 : A+B or A-B【暴力枚举】

    2080 : A+B or A-B(点击左侧标题进入zznu原题页面) 时间限制:1 Sec 内存限制:0 MiB提交:8 答案正确:3 提交 状态 讨论区 题目描述 Give you three s ...

  2. 做fzu oj 1045 做减法学到的sprintf()函数

    题目 做题一直输不出答案,于是就上网去百度了这题的解题,发现解答十分的简短,而且其中我看见了平时没见过的函数,sprintf(). 于是就百度sprintf()的使用. 如下: 函数功能:把格式化的数 ...

  3. poj 2117 Electricity【点双连通求删除点后最多的bcc数】

    Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4727   Accepted: 1561 Descr ...

  4. (haut oj 1261 ) 地狱飞龙 利用不定积分求值

    题目链接:http://218.28.220.249:50015/JudgeOnline/problem.php?id=1261 题目描述 最近clover迷上了皇室战争,他抽到了一种地狱飞龙,很开心 ...

  5. Light OJ 1296:Again Stone Game(SG函数打表找规律)

    Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains ...

  6. oj 1002题 (大数题)

    #include <stdio.h> #include <string.h> int main(void) { int q,j,h,k,l; int d; ],s2[];//题 ...

  7. 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

    题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...

  8. hdu 2117:Just a Numble(水题,模拟除法运算)

    Just a Numble Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. 九度OJ 1049:字符串去特定字符 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8499 解决:3860 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和 ...

随机推荐

  1. leetcode1186 Maximum Subarray Sum with One Deletion

    思路: 最大子段和的变体,前后两个方向分别扫一遍即可. 实现: class Solution { public: int maximumSum(vector<int>& arr) ...

  2. 基于 Spring + Atomikos + Mybatis的多数据源配置(含有BaseDao,BaseService)

    1.spring配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  3. AD域环境搭建

    1.安装Windows server服务器 我安装的是Windows server 2012 Standard x64 下载地址:https://pan.baidu.com/s/1dZ_B5JIEit ...

  4. python+unittest框架第一天unittest之简单认识Test Fixure:测试固件【8月17更新】

    20万的慢慢会实现的吧,hhh unittest框架,我就不在介绍了,百度有很详细的介绍. 我们只要了解: 1.unittest是单元测试框架 2.它提供用例组织与执行:在实际工作中案例可能有上百条, ...

  5. 乐字节Java反射之一:反射概念与获取反射源头class

    一.Java反射机制概念 “程序运行时,允许改变程序结构或变量类型,这种语言称为动态语言”,如Python, Ruby是动态语言:显然C++,Java,C#不是动态语言,但是JAVA有着一个非常突出 ...

  6. qt qml中的Tabview使用心得

    彩云之南的天是如此湛蓝,天上落下的水是如此清澈. 最近在qt5.5下使用TabView,如下. 1) currentIndex变量很好用,其对应当前被显示的tab,其值变化时还会触发onCurrent ...

  7. 27.Spark中transformation的介绍

    Spark支持两种RDD操作:transformation和action.transformation操作会针对已有的RDD创建一个新的RDD: 而action则主要是对RDD进行最后的操作,比如遍历 ...

  8. Linux中查找最耗CPU的Java代码问题

    第一步: 查看消耗CPU最高的进程PID [lolaage@web2 tomcat-ns]$ top top - 13:23:32 up 42 days, 19:11,  3 users,  load ...

  9. Mongodb: com.mongodb.MongoSocketReadException: Prematurely reached end of stream

    saveLocationInfo errorcom.mongodb.MongoSocketReadException: Prematurely reached end of stream at com ...

  10. sqlite lib导入

    依赖 1.System.Data.SQLite 2.SqlKata //https://www.nuget.org/profiles/SQLite //http://system.data.sqlit ...