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. [原]Golang FileServer

    转载请注明出处 今天我们用go来搭建一个文件服务器FileServer,并且我们简单分析一下,它究竟是如何工作的.知其然,并知其所以然! 首先搭建一个最简单的,资源就挂载在服务器的根目录下,并且路由路 ...

  2. Java NIO、NIO.2学习笔记

    相关学习资料 http://www.molotang.com/articles/903.html http://www.ibm.com/developerworks/cn/education/java ...

  3. MySQL学习笔记01-MYSQL安装

    一 MySQL简介 MySQL是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司. MySQL 最流行的关系型数据库管理系统. MySQL分为企业版和社区版. ...

  4. HD 2177(威佐夫博弈 入门)

    取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. map 几种遍历方法

    public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...

  6. 在Vs2012 中使用SQL Server 2012 Express LocalDB打开Sqlserver2012数据库

    http://www.cnblogs.com/huangtailang/p/4221164.html 背景:个人电脑中使用的是VS2012,数据库为2008R2,最近需要打开一个SqlServer20 ...

  7. --hdu 2570 迷瘴(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2570 Ac code: #include<stdio.h> #include<std ...

  8. windows2008R2安全加固

    一.更改终端默认端口号 步骤: 1.运行regedit 2.[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\W ...

  9. ASP.NET MVC 4 跨域

    <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...

  10. 我的css释疑-float line-height inline-block vertical-align

    markdown的图片和链接格式相类似: [链接文字/图片的alt text] (链接地址/ 图片的地址), 只是图片要在前面加上感叹号! 当内容中含有图片的时候,如果图片的高度大于行高,则含有图片 ...