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

poj 1311 Doing Windows

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

poj 1311 Doing Windows

#include <cstdio>#include <algorithm>#include <cmath>using namespace std;double r[4];int is_integer(double t){    int i=t+0.0000005;    if(fabs(t-i)<0.000001)        return i;    return 0;}int try_height(int i,int sw){    double dh=sw/r[i];    int h=dh+.0000005;    if(fabs(h-dh)<0.000001)        return h;    return -1;}int try_weight(int i,int sh){    double dw=sh*r[i];    int w=dw+.0000005;    if(fabs(w-dw)<0.000001)        return w;    return -1;}bool fill(int sw, int sh){    int w,h,tw,th,j,k,a[4]={0,1,2,3};    for(j=0;j<24;j++)    {        tw=sw,th=sh;        for(k=0;k<4&&th&&twk++)        { h=try_height(a[k],tw); if(h!=-1&&h<=th)     th-=h; else {     w=try_weight(a[k],th);     if(w==-1||w>tw)         break;     tw-=w; }        }        if (k==4&&(!tw||!th)) return true;        next_permutation(a,a+4);    }    return false;}int fit(int w ,int i,int j){    double h=w/(r[i]+r[j]);    int ret=is_integer(h);    if(is_integer(h*r[i]) && is_integer(h*r[j]))        return ret;    return 0;}bool mixture(int sw,int sh){    int a[4]={0,1,2,3};    int i,j,k,h1,h2,tw,th;    for(i=0;i<24;i++)    {        tw=sw,th=sh;        h1=fit(tw,a[0],a[1]);        h2=fit(tw,a[2],a[3]);        if(h1&&h2&&h1+h2==sh) return true;        next_permutation(a,a+4);    }    return false;}int main(){    int i,t,w,h,sw,sh;    for(t=1;scanf("%d%d",&sw,&sh),sw+sh;t++)    {        bool found=false;        for(i=0;i<4;i++)        { scanf("%d%d",&w,&h); r[i]=w*1.0/h;        }        if(fill(sw,sh)) found=true;        else        { if(mixture(sw,sh))     found=true; else {     for(i=0;i<4;i++)         r[i]=1/r[i];     found=mixture(sh,sw); }        }        if(found) printf("Set %d: Yesn",t);        else printf("Set %d: Non",t);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375552.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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