《算法竞赛入门经典》第四章小结
来源:互联网 发布:linux tail 最后一页 编辑:程序博客网 时间:2024/04/25 07:33
题目:编写一个函数solve,给定浮点数a,b,c,d,e,f,求解方程组ax+by=c, dx+ey=f.
任务1:使用assert宏,让解不唯一时异常退出。
任务2: 解不唯一时仍正常返回,但调用者有办法知道解的数量(无解,唯一解,无穷多组解)。
思考:函数的参数都有哪些,各是什么类型?
//任务1#include <stdio.h>#include <assert.h>double fucx(double a,double b,double c, double d,double e,double f){assert( (a*e-b*d)!=0 );return (c*e-b*f)/(a*e-b*d);} double fucy(double a,double b,double c, double d,double e,double f){assert( (a*e-b*d)!=0 );return (a*f-c*d)/(a*e-b*d);}int main(){double a,b,c,d,e,f;double x,y;scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);x=fucx(a,b,c,d,e,f);printf("\n");y=fucy(a,b,c,d,e,f);printf("%lf %lf\n",x,y);return 0;}
//任务2#include <stdio.h>#include <assert.h>int decide(double a,double b,double c, double d,double e,double f){if(a*e==b*d){if( (c*e==b*f)&&(a*f==c*d) ){return 2;}else{return 3;}}elsereturn 1;} int main(){double a,b,c,d,e,f;double x,y;scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);int out;out=decide(a,b,c,d,e,f);if(out==1){printf("%lf %lf\n",(c*e-b*f)/(a*e-b*d),(a*f-c*d)/(a*e-b*d));}if(out==2)printf("There is infinite solution.\n");if(out==3)printf("There is no solution.\n");return 0;}
- 《算法竞赛入门经典》第四章小结
- 算法竞赛入门经典第四章笔记
- 算法竞赛入门经典-第四章源代码
- 算法竞赛入门经典 第四章答案
- acm算法竞赛入门经典第四章
- 算法竞赛入门经典第四章习题
- 《算法竞赛入门经典》第四章总结
- 算法竞赛入门经典第四章
- 算法竞赛入门经典第四章例题总结:
- 算法竞赛入门经典第四章:部分习题解答
- 算法竞赛入门经典第二版 第四章
- 算法竞赛入门经典第1章【小结与习题】
- 算法竞赛入门经典第2章【小结和习题】
- 算法竞赛入门经典第3章【小结与习题】
- 算法竞赛入门经典第二章【小结与习题】
- 算法竞赛入门经典第3章【小结与习题】
- 算法竞赛入门经典chapter4:本章小结
- 算法竞赛入门经典第四章 【uvaoj在线习题(二)】
- php支持json
- Struts2中OGNL,valueStack,stackContext的学习
- NYOJ-511-移动小球
- php支持json2
- python成长日记2:文件的输入输出
- 《算法竞赛入门经典》第四章小结
- 需要懂得的java专业名词
- Sicily 1344. 数列
- 重新做回菜鸟,初次使用wine
- Design Patterns in Java
- yum和apt-get用法及区别 (转)
- css中float浮动问题(1)
- 献给奋斗在一线的程序员们!!!
- strstr和strchr函数的用法