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. 5.Android之image控件学习

    Android中经常用到图片,比如图片浏览.图标等等,今天学习下image控件,image控件主要有ImageButton和ImageView两种. (1)ImageButton 在布局文件增加: & ...

  2. MySQL安装最后一步apply security settings错误

    网上查了很久都是说删除各种文件什么的,直接百度apply security settings,说是mysql没卸载干净.不是的. 看日志发现 You must SET PASSWORD before ...

  3. 【bzoj1050】 旅行comf

    http://www.lydsy.com/JudgeOnline/problem.php?id=1050 (题目链接) 题意 给出一个无向图,求图中两点间某条路径使得最大权值除以最小权值的值最小 So ...

  4. 安卓系统源码编译系列(六)——单独编译内置浏览器WebView教程

    原文                   http://blog.csdn.net/zhaoxy_thu/article/details/18883015                 本文主要对从 ...

  5. ci创建zip

    public function createZip() { $this->load->library("zip"); $name = "test.text&q ...

  6. java连接各种数据库代码大全

    1.Oracle8/8i/9i数据库(thin模式)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();S ...

  7. apache配置多个虚拟主机

    设置apache 多个虚拟目录记录 #配置第2个虚拟目录<VirtualHost 127.0.0.2:80>ServerName www.xx.comDocumentRoot " ...

  8. Java 参数的一些心得

    java 对象入参是传入的是引用(一块内存), 基础类型是值(复制内容),测试代码如下 public class TestA { private String name; public String ...

  9. 浅谈setTimeout函数和setInterval函数

    前几天学了js,看到了两个非常有趣的函数,他们分别是setTimeout函数和setInterval函数,这两个函数能使网页呈现非常一些网页中比较常见的效果,比如说图片轮播,等一些非常好玩的效果.下面 ...

  10. C语言内存对齐详解(1)

    一.什么是字节对齐,为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的内存地址访问,这 ...