Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- double f(double x){
- return x*x*x - 3*x*x + 9*x - 8;
- }
- //惹かれ合う二者の運命
- void TheFateOfTwoPeopleWhoAreAttracted(double somethingWhoIsTheRootOfTheWorld, double thoseWhoDoNotKnowImpurityYet){
- //生命、宇宙、そして万物についての究極の疑問の答え
- int answerToTheUltimateQuestionAboutLifeUniverseAndAllThings = 42;
- while(answerToTheUltimateQuestionAboutLifeUniverseAndAllThings){
- //かつて世界の根源だったもの
- double whatWasTheRootOfTheWorld = somethingWhoIsTheRootOfTheWorld;
- //新たな決意
- double newDetermination = (somethingWhoIsTheRootOfTheWorld*f(thoseWhoDoNotKnowImpurityYet) - thoseWhoDoNotKnowImpurityYet*f(somethingWhoIsTheRootOfTheWorld))
- / (f(thoseWhoDoNotKnowImpurityYet)-f(somethingWhoIsTheRootOfTheWorld));
- //もしも新たな決意が世界の根源となるなら世界の根源の変革の時、まだ穢れを知らぬなら知らぬままに。
- if(f(newDetermination) > 0){
- thoseWhoDoNotKnowImpurityYet = newDetermination;
- }
- else if(f(newDetermination) < 0){
- somethingWhoIsTheRootOfTheWorld = newDetermination;
- }
- else{
- //節子それ近似解とちがう、厳密解や
- cout << "x = " << newDetermination << endl;
- return;
- }
- //世界の根源の変革が収束に向かうなら、ラグナロクの始まりが訪れる。
- if(fabs(whatWasTheRootOfTheWorld - somethingWhoIsTheRootOfTheWorld) < 0.00001){
- //全てを終わらせる時
- break;
- }
- }
- //この世の解
- cout << somethingWhoIsTheRootOfTheWorld << " <= x <= " << thoseWhoDoNotKnowImpurityYet << endl;
- return;
- }
- int main(void){
- //要ははさみうち法
- TheFateOfTwoPeopleWhoAreAttracted(0, 5);
- return 0;
- }
Add Comment
Please, Sign In to add comment