ACboy needs your help

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5963    Accepted Submission(s):
3250

Problem Description
ACboy has N courses this term, and he plans to spend at
most M days on study.Of course,the profit he will gain from different course
depending on the days he spend on it.How to arrange the M days for the N courses
to maximize the profit?
 
Input
The input consists of multiple data sets. A data set
starts with a line containing two positive integers N and M, N is the number of
courses, M is the days ACboy has.
Next follow a matrix A[i][j],
(1<=i<=N<=100,1<=j<=M<=100).A[i][j] indicates if ACboy spend j
days on ith course he will get profit of value A[i][j].
N = 0 and M = 0 ends
the input.
 
Output
For each data set, your program should output a line
which contains the number of the max profit ACboy will gain.
 
Sample Input
2 2
1 2
1 3
2 2
2 1
2 1
2 3
3 2 1
3 2 1
0 0
 
Sample Output
3
4
6
 
Source
 
Recommend
lcy   |   We have carefully selected several similar
problems for you:  2159 1561 2602 3033 2955 

对于两个最简的分数 a / b, c / d 把他们两个的最小公倍数 x / y 也设为一个分数形式,那么这个 x 一定能够被 a , c整除, y 一定能够整除 b , d。那么要求得最小公倍数,那么肯定是分子尽量小,即 a , c 的最小公倍数, 分母尽量大, 即 b , d 的最大公约数。

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
if (b==) return a;
else return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
int main()
{
ll i,j,t,fz1,fz2,fm1,fm2,fz,fm,len1,len2,len3,len4,tmp;
char c;
cin>>t;
while (t--)
{
cin>>fz1>>c>>fm1;
cin>>fz2>>c>>fm2;
tmp=gcd(fz1,fm1);
fz1/=tmp;
fm1/=tmp;
tmp=gcd(fz2,fm2);
fz2/=tmp;
fm2/=tmp;
//cout<<tmp<<" "<<fz2<<" "<<fm2<<endl;
//fm=gcd(fm1,fm2); 题目给的分数不是最简!!!!
//fz=lcm(fz1,fz2);fz是俩分子的最小公倍数 后化简的话 fm已经变成两个数的最大公约数了 没法被用作化简了
//cout<<gcd(fz,fm)<<"aaaaaaaaa"<<endl;
//fz/=gcd(fz,fm);
//fm/=gcd(fz,fm);//用abcd fz1,fz2写成fz1,fm1了
if (gcd(fm1,fm2)==)
cout<<lcm(fz1,fz2)<<endl;
else
cout<<lcm(fz1,fz2)<<"/"<<gcd(fm1,fm2)<<endl;
} return ;
}

//很久之前做的很烦的一道题。

HDU1712周期的更多相关文章

  1. react组件的生命周期

    写在前面: 阅读了多遍文章之后,自己总结了一个.一遍加强记忆,和日后回顾. 一.实例化(初始化) var Button = React.createClass({ getInitialState: f ...

  2. 浅谈 Fragment 生命周期

    版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Fragment 文中如有纰漏,欢迎大家留言指出. Fragment 是在 Android 3.0 中 ...

  3. C# MVC 5 - 生命周期(应用程序生命周期&请求生命周期)

    本文是根据网上的文章总结的. 1.介绍 本文讨论ASP.Net MVC框架MVC的请求生命周期. MVC有两个生命周期,一为应用程序生命周期,二为请求生命周期. 2.应用程序生命周期 应用程序生命周期 ...

  4. UIViewController生命周期-完整版

    一.UIViewController 的生命周期 下面带 (NSObject)的方法是NSObject提供的方法.其他的都是UIViewController 提供的方法. load   (NSObje ...

  5. angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation

    今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:

  6. Spring中Bean的作用域、生命周期

                                   Bean的作用域.生命周期 Bean的作用域 Spring 3中为Bean定义了5中作用域,分别为singleton(单例).protot ...

  7. Autofac - 生命周期

    实例生命周期决定在同一个服务的每个请求的实例是如何共享的. 当请求一个服务的时候,Autofac会返回一个单例 (single instance作用域), 一个新的对象 (per lifetime作用 ...

  8. 【微信小程序开发•系列文章六】生命周期和路由

    这篇文章理论的知识比较多一些,都是个人观点,描述有失妥当的地方希望读者指出. [微信小程序开发•系列文章一]入门 [微信小程序开发•系列文章二]视图层 [微信小程序开发•系列文章三]数据层 [微信小程 ...

  9. Xamarin.Android活动的生命周期

    一.前言 用过Android手机的人一定会发现一种现象,当你把一个应用置于后台后,一段时间之后在打开就会发现应用重新打开了,但是之前的相关的数据却没有丢失.可以看出app的“生命”是掌握在系统手上的, ...

随机推荐

  1. 学习笔记--博弈组合-SG函数

    fye学姐的测试唯一的水题.... SG函数是一种游戏图每个节点的评估函数 具体定义为: mex(minimal excludant)是定义在整数集合上的操作.它的自变量是任意整数集合,函数值是不属于 ...

  2. Linux Rootkit Sample && Rootkit Defenser Analysis

    目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...

  3. ubuntu安装spark

    1.先得准备环境,需要JAVA环境,还有Python环境(默认会有) JAVA下载JDK之后配置JAVA环境变量 export JAVA_HOME=/opt/jdk1..0_45 export JRE ...

  4. Core Animation编程指南

    本文是<Core Animation Programming Guide>2013-01-28更新版本的译文.本文略去了原文中关于OS X平台上Core Animation相关内容.因为原 ...

  5. Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang

    Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang Recruit Ponpare is Japan's leading ...

  6. The mean shift clustering algorithm

    The mean shift clustering algorithm MEAN SHIFT CLUSTERING Mean shift clustering is a general non-par ...

  7. Conjugate prior relationships

    Conjugate prior relationships The following diagram summarizes conjugate prior relationships for a n ...

  8. awk命令--update20150120

    简介 awk是一个强大的文本分析工具,把文件逐行读入,以空格为默认分隔符分割成field,切开的部分再进行各种分析处理. 模式和动作: 任何awk语句都是由模式和动作组成,模式部分决定动作语句何时触发 ...

  9. vs2012 智能提示消失解决办法

    一般你可以重启vs就可以解决问题,最蛋疼的是你重启也没用.只能重置,再不行就重装vs,再不行你就重装系统......扯淡了... 重置Visual Studio可以解决此问题, 方法:开始->M ...

  10. Linux中如何查看文件的最初创建时间

    查看 一个文件的 最初创建时间: Linux中如何查看文件的最初创建时间  linux     目前Linux没有直接查看创建文件的命令,你只能通过文件是否被修改过来进行判断. //查看代码stat  ...