厦大oj1438简单题、数学题(积分、几何概率、求最大公约数)
2013-04-20 18:20
357 查看
#include<iostream> #include<string> #include<fstream> using namespace std; int time_to_int(string time){ int time_int = 0; int hour = 0; int minute = 0; if(time[0] != '0'){ hour = (int)(time[0] - 48); time_int += hour * 60 * 10; } if(time[1] != '0'){ hour = (int)(time[1] - 48); time_int += hour * 60; } if(time[3] != '0'){ minute = (int)(time[3] - 48); time_int += minute * 10; } if(time[4] != '0'){ minute = (int)(time[4] - 48); time_int += minute; } return time_int; } int gcd(int a, int b){ if(a<0) return gcd(-a, b); if(b<0) return gcd(a, -b); return (b == 0)? a : gcd(b, a % b); } int main(){ string s1, s2; int fenzi; int fenmu; int m, time1, time2, time_dis; //ifstream ifs("shuju.txt"); //ifs>>s1>>s2>>m;// cin>>s1>>s2>>m; time1 = time_to_int(s1); time2 = time_to_int(s2); time_dis = time2 - time1; if(time_dis < m){ cout<<1<<"/"<<2; //system("pause"); return 0; } //cout<<time_dis<<endl;// fenzi = 2 * (time_dis - m) * m + m * m; fenmu = 2 * time_dis * time_dis; //cout<<fenzi<<fenmu<<endl; int zuidagongyueshu = gcd(fenzi, fenmu); //cout<<zuidagongyueshu<<endl; fenzi /= zuidagongyueshu; fenmu /= zuidagongyueshu; cout<<fenzi<<"/"<<fenmu; //system("pause"); return 0; }
相关文章推荐
- 厦大oj1438简单题、map
- 山东省第五届省赛 A题 angry_birds_again_and_again(简单数学 积分问题)
- NEUOJ1207 Birthday present (简单数学)
- 物理方法解决数学问题(一):从一个简单的平面几何题谈起
- zzulioj--1600--直线与圆(简单数学几何)
- lightoj Triangle Partitioning 1073 (简单数学几何判断相似)
- zzuoj--1001--汽水瓶(简单数学)
- zzulioj--1600--直线与圆(简单数学几何)
- 1204 ACdream Integration of Polynomial(数学:简单求积分)
- 南阳OJ 一个简单的数学题
- zzuoj--1001--汽水瓶(简单数学)
- USTC OJ — 1003 Fibonacci Numbers(组合数学, 简单题)
- 厦大C语言上机 1391 简单的几何问题
- Codeforces 570B Simple Game 概率求解,简单数学思维
- 哈理工OJ 2214 Judge(简单的数学题)
- 简单数学题或者计算几何:Codeforces 659D-Bicycle Race
- [ACM] sdut 2877 angry_birds_again_and_again (简单数学积分)
- 【light-oj】-1104 - Birthday Paradox(数学,概率)
- 【整理】简单的数学期望和概率DP
- hdu 2201 (简单数学概率)