栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2260 The Balance

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2260 The Balance

#include<iostream>#include<string.h>#include<map>#include<stdio.h>#include<algorithm>using namespace std;enum {    SIZ = 1000000000,};int w[2],d;int c[2];int num, weight;void testOne(int one){    if(d % w[one] !=0)        return;    int t = d / w[one];    if(t < num || (t==num) && d < weight){        c[one] = t, c[1-one]=0;        num = t, weight = d;    }}void testSum(){    int x,y;    for(y = 0; d>=y*w[1] && (d-y*w[1])%w[0]!=0;y++)        ;    if(d>=y*w[1]){        x = (d-y*w[1])/w[0];        int t = x + y;        if(t < num || (t==num) && d < weight){ c[0] = x, c[1]=y; num = t, weight = d;        }    }    for(x=0; d>=x*w[0] && (d-x*w[0])%w[1]!=0;x++)         ;    if(d>=x*w[0]){        y = (d-x*w[0])/w[1];        int t = x + y;        if(t < num || (t==num) && d< weight){ c[0] = x, c[1]=y; num = t, weight = d;        }    }}void testSub(int one){    int q[2];    q[1-one] = 0;    q[one] = d / w[one];    while( q[one]*w[one] != d + q[1-one] *w[1-one]){        if(q[one]*w[one]<d+q[1-one]*w[1-one]){ q[one]++;        } else { q[1-one]++;        }    }    int t = q[one] + q[1-one];    int s = q[one]*w[one] + q[1-one]*w[1-one];    if(t < num || (t==num) && s < weight){        c[one] = q[one]; c[1-one] = q[1-one];        num = t, weight = s;    }}void fun(){    num = weight = SIZ;    testOne(0);    testOne(1);    testSum();    testSub(0);    testSub(1);    cout<<c[0]<<" "<<c[1]<<endl;}int main(){    while(cin>>w[0]>>w[1]>>d && w[0]+w[1]+d){        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378516.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号