zoukankan      html  css  js  c++  java
  • bzoj1024题解

    【解题思路】

      爆搜,状态f(r,x,y)表示剩下r刀,边长为x和y,对于每个状态枚举切成两块后的长度比或宽度比。复杂度o((n/2)n)。

    【参考代码】

      1 #include <algorithm>
      2 #include <cstdio>
      3 #define REP(I,start,end) for(int I=(start);I<=(end);I++)
      4 #define PER(I,start,end) for(int I=(start);I>=(end);I--)
      5 #define REPs(I,start,end,step) for(int I=(start);I<=(end);I+=(step))
      6 #define PERs(I,start,end,step) for(int I=(start);I>=(end);I-=(step))
      7 #define maxint 32767
      8 #define maxlongint 2147483647
      9 #define maxint64 9223372036854775807ll
     10 using namespace std;
     11 typedef unsigned short US;
     12 typedef unsigned long UL;
     13 typedef long long LL;
     14 typedef unsigned long long ULL;
     15 inline int getint()
     16 {
     17     char ch=getchar();
     18     while((ch<'0'||ch>'9')&&ch!='-')
     19         ch=getchar();
     20     int result=0;
     21     bool impositive=ch=='-';
     22     if(impositive)
     23         ch=getchar();
     24     while(ch>='0'&&ch<='9')
     25     {
     26         result=(result<<3)+(result<<1)+ch-'0';
     27         ch=getchar();
     28     }
     29     return impositive?-result:result;
     30 }
     31 inline int putint(int n)
     32 {
     33     int result=1;
     34     char* sav=new char[20];
     35     bool impositive=n<0;
     36     if(impositive)
     37     {
     38         putchar('-');
     39         n=-n;
     40     }
     41     sav[0]=n%10+'0';
     42     while(n/=10)
     43         sav[result++]=n%10+'0';
     44     PER(i,result-1,0)
     45         putchar(sav[i]);
     46     delete []sav;
     47     return result+impositive;
     48 }
     49 inline LL getLL()
     50 {
     51     char ch=getchar();
     52     while((ch<'0'||ch>'9')&&ch!='-')
     53         ch=getchar();
     54     LL result=0ll;
     55     bool impositive=ch=='-';
     56     if(impositive)
     57         ch=getchar();
     58     while(ch>='0'&&ch<='9')
     59     {
     60         result=(result<<3)+(result<<1)+ch-'0';
     61         ch=getchar();
     62     }
     63     return impositive?-result:result;
     64 }
     65 inline int putLL(LL n)
     66 {
     67     int result=1;
     68     char* sav=new char[20];
     69     bool impositive=n<0;
     70     if(impositive)
     71     {
     72         putchar('-');
     73         n=-n;
     74     }
     75     sav[0]=n%10+'0';
     76     while(n/=10)
     77         sav[result++]=n%10+'0';
     78     PER(i,result-1,0)
     79         putchar(sav[i]);
     80     delete []sav;
     81     return result+impositive;
     82 }
     83 template<typename integer> inline int read_int(integer &n)
     84 {
     85     char ch=getchar();
     86     while((ch<'0'||ch>'9')&&ch!='-')
     87         ch=getchar();
     88     int result=n=integer(0);
     89     bool impositive=ch=='-';
     90     if(impositive)
     91         ch=getchar();
     92     while(ch>='0'&&ch<='9')
     93     {
     94         n=(n<<3)+(n<<1)+integer(ch-'0');
     95         result++;
     96         ch=getchar();
     97     }
     98     if(impositive)
     99     {
    100         n=-n;
    101         result++;
    102     }
    103     return result;
    104 }
    105 template<typename integer> inline int write_int(integer n)
    106 {
    107     int result=1;
    108     char* sav=new char[20];
    109     bool impositive=n<0;
    110     if(impositive)
    111     {
    112         putchar('-');
    113         n=-n;
    114     }
    115     sav[0]=n%10+'0';
    116     while(n/=10)
    117         sav[result++]=n%10+'0';
    118     PER(i,result-1,0)
    119         putchar(sav[i]);
    120     delete []sav;
    121     return result+impositive;
    122 }
    123 template<typename T> inline bool getmin(T &target,T pattern)
    124 {
    125     bool can=pattern<target;
    126     if(can)
    127         target=pattern;
    128     return can;
    129 }
    130 template<typename T> inline bool getmax(T &target,T pattern)
    131 {
    132     bool can=pattern>target;
    133     if(can)
    134         target=pattern;
    135     return can;
    136 }
    137 //==========================================Header Template================================================
    138 #include <iomanip>
    139 #include <iostream>
    140 double DFS(int rest,double _x,double _y)
    141 {
    142     if(rest==1)
    143         return _x>_y?_x/_y:_y/_x;
    144     double result=maxlongint;
    145     REP(i,1,rest>>1)
    146     {
    147         long double x0=_x/rest,y0=_y/rest,_r=rest-i;
    148         getmin(result,min(max(DFS(i,x0*i,_y),DFS(_r,x0*_r,_y)),max(DFS(i,_x,y0*i),DFS(_r,_x,y0*_r))));
    149     }
    150     return result;
    151 }
    152 int main()
    153 {
    154     int x=getint(),y=getint(),n=getint();
    155     cout<<setiosflags(ios::fixed)<<setprecision(6)<<DFS(n,x,y)<<endl;
    156     return 0;
    157 }
    View Code
    We Secure, We Contain, We Protect.
  • 相关阅读:
    JS 实现页面跳转
    JavaScript 获取指定的cookie值
    Jquery为单选框checkbox绑定单击事件
    “25岁博导”是“破五唯”的 正面榜样 还是 反面教材 ???
    国产软件如何让人再次失望——!20824 mindspore1.3.0gpu version can not compile from source code, because openmpi source code has bug
    sqlserver触发器引起的死锁问题
    Oracle客户端tnsnames.ora连接配置
    win7 调整C盘大小,不使用PQ
    C# 适合vs 2008和vs 2010的变量高亮highlight工具
    C# Response.Redirect引起的错误
  • 原文地址:https://www.cnblogs.com/spactim/p/6433936.html
Copyright © 2011-2022 走看看