wstlwl 发表于 2015-11-26 07:30:23

【codechef】Chef and His Friend (甲乙相遇的概率,分类)


  

Input:
2
2 2 1 1
1 1 1 1
Output:
0.750000
1.000000
http://www.codechef.com/JUNE15/problems/FRNDMTNG
  



  考虑问题要全。。
  #include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx={0,0,-1,1};int dy={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define mod 1e9+7
#define ll long long
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
double T1,T2,t1,t2;
cin>>T1>>T2>>t1>>t2;
if(t1>T2)
t1=T2;
if(t2>T1)
t2=T1;
double s1=(T2-t1)*(T2-t1)/2;
double s2=(T1-t2)*(T1-t2)/2;
if(T1-t2>T2)
s2-=(T1-t2-T2)*(T1-t2-T2)/2;//注意考虑到
if(T2-t1>T1)
s1-=(T2-t1-T1)*(T2-t1-T1)/2;//注意考虑到
printf(&quot;%.6lf\n&quot;,(T1*T2-s1-s2)/(T1*T2));
}
return 0;
}
页: [1]
查看完整版本: 【codechef】Chef and His Friend (甲乙相遇的概率,分类)