Sixth week of training the concept and methods of mathematics UVA 11722 Geometrical overview

Source: Internet
Author: User

---restore content starts---

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471

Test instructions, two trains, will stay at the same site for the time period of [t1,t2],[s1,s2], and ask the probability that two trains will meet at this site.

Idea, enumerate each case, draw out the intersection of the two trains, and then ask the probabilities in this interval

#include"iostream"#include"Cstdio"#include"Cmath"using namespacestd;intCA;DoubleT1,t2,s1,s2,w,ans;DoubleCaculate (Doubleb) {    inty1=t1+b,y2=t2+b; if(Y2&LT;S1)return 0; if(y1<S1) {        if(Y2&LT;S2)return 0.5* (Y2-S1) * (y2-S1); Else return 0.5* (S2-S1) * (2*y2-s1-S2); }    if(y1<S2) {        if(Y2&LT;S2)return 0.5* (T2-T1) * (y1-s1+y2-S1); Else return(T2-T1) * (S2-S1)-0.5* (s2-y1) * (s2-y1); }    return(T2-T1) * (s2-s1);}voidInit () {scanf ("%LF%LF%LF%LF%LF",&t1,&t2,&s1,&s2,&w);}voidWork () {ans= (Caculate (w)-caculate (-W))/((T2-T1) * (s2-s1));}voidPrint () {printf ("Case #%d:%.8f\n", ca++, ans);}intMain () {intT; CA=1; CIN>>u;  while(t--) {Init ();     Work ();    Print (); }    return 0;}
View Code

---restore content ends---

Sixth week of training the concept and methods of mathematics UVA 11722 Geometrical overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.