【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

【codechef】Chef and His Friend (甲乙相遇的概率,分类)_第1张图片

考虑问题要全。。

#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-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("%.6lf\n",(T1*T2-s1-s2)/(T1*T2)); 
	} 
	return 0;
}  


你可能感兴趣的:(【codechef】Chef and His Friend (甲乙相遇的概率,分类))