Summer warm up B. Download speed

Source: Internet
Author: User

Recently, Nono finally ended the annual 12-month hibernation, the first thing to wake up--watch the movie!! Nono found that there have been a lot of good and powerful films in the last year, such as this, this, and this. So Nono directly threw all these movies into the download list. Known Nono downloaded n movies, of which part I movie size si, the movie maximum download speed will not exceed VI, at any time the download speed of all movies will not exceed Vt. Now Nono want to know how long it will take at least to get all of these movies under these conditions. Input multiple sets of inputs. The first behavior of each set of inputs is two integers n,vt (0<n≤106, 0<vt≤109). The next n rows of two integers per line represent Si, Vi (0<si,vi≤1000). The input ends with EOF. Output

For each set of data, output an approximate fraction of the minimum time required to download a full movie.

Sample Input
3 67 45 23 41 106 2
Sample Output
5/23/1
The problem begins with complexity, and all tasks start at the same time, and the maximum time to compare a single task.

The first version of the test all the data are no problem, do not know where the wrong is always WA
#include <stdio.h>structdongser{intA; intb;};structDongser D;intda,db;voidSimintIintj) {    intk=i-1; if(I==J) {i=j=1;} if(i%j==0) {i=i/j;j=1;d a=i;db=j;return;} if(j%i==0) {j=j/i;i=1;d a=i;db=j;return;}  while(1)    {        if(k==1) {da=i;db=j;return;} if(i%k==0&&j%k==0) {i=i/k;j=j/K;} Else{k--;} }}intMain () {intI,J,K,N,VT; Doublem,t,p;  while(SCANF ("%d%d", &AMP;N,&AMP;VT)! =EOF) {         for(i=1; i<=n;i++) {scanf ("%d%d",&d.a,&d.b); J+=d.a; T=d.a/d.b; if(t>p) {p=t;k=i;da=d.a;db=d.b;} } m=j/VT; if(m>=p) {Da=j;db=vt;sim (da,db);p rintf ("%d/%d\n", da,db);} if(m<p) {SIM (da,db);p rintf ("%d/%d\n", da,db);} I=j=k=n=vt=m=t=p=da=db=d.a=d.b=0; }    return 0;}
View Code

AC Version:
#include <iostream>#include<cstdio>using namespacestd;intN, VT;intGCD (intAintb) {  while(b! =0){ intT a%= b; t = A; A = b; b =t;}returnA;}intMain () {Ios::sync_with_stdio (false);  while(Cin >> N >>VT) { intsum =0;intrs =0, RV =1;  for(inti =0; I < n; ++i) {ints, v; CIN>> s >> v; sum + = s;if((Double) Rs/rv < (Double) s/v) {rs = s; rv = V;}}if((Double) Rs/rv < (Double) (SUM/VT) {rs = sum; RV = VT;}intK = gcd (rs, RV); cout << rs/k <<"/"<< rv/k << Endl; }return 0; }
View Code

Summer warm up B. Download speed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.