• 搜索复习-中级水题


    bzoj1024 生日快乐

    Description

      windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕。现在包括windy,一共有 N 个人来分这块大蛋糕,要求每个人必须获得相同面积的蛋糕。windy主刀,每一切只能平行于一块蛋糕的一边(任意一边),并且必须把这块蛋糕切成两块。这样,要切成 N 块蛋糕,windy必须切 N-1 次。为了使得每块蛋糕看起来漂亮,我们要求 N块蛋糕的长边与短边的比值的最大值最小。你能帮助windy求出这个比值么?

    Input

      包含三个整数,X Y N。1 <= X,Y <= 10000 ; 1 <= N <= 10

    Output

      包含一个浮点数,保留6位小数。

    Sample Input

    5 5 5

    Sample Output

    1.800000
     
    这道题是wjx说LLJ大佬推荐的水题,然后我看了很久,不知道应该怎么做。
    最后才发现是一个裸的搜索。。。
    因为面积相同可以直接按照比例划。所以就比较好搞了,代码也很短。
    //Serene
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    const double INF=1e100;
    double x,y;int n;
    
    double dfs(double x,double y,int tot) {
    	if(tot==1) return max(x/y,y/x);
    	double rs=INF;
    	for(int i=1;i<=tot/2;++i) {
    		rs=min(rs,max(dfs(x/tot*i,y,i),dfs(x-x/tot*i,y,tot-i)));
    		rs=min(rs,max(dfs(x,y/tot*i,i),dfs(x,y-y/tot*i,tot-i)));
    	}
    	return rs;
    }
    
    int main() {
    	cin>>x>>y>>n;
    	printf("%.6lf",dfs(x,y,n));
    	return 0;
    }
    

     

    洛谷P1463 反素数ant

    题目描述

    对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。

    如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数。例如,整数1,2,4,6等都是反质数。

    现在给定一个数N,你能求出不超过N的最大的反质数么?

    输入输出格式

    输入格式:

    一个数N(1<=N<=2,000,000,000)。

    输出格式:

    不超过N的最大的反质数。

    输入输出样例

    输入样例#1:
    1000
    输出样例#1:
    840

    题解
    一开始一直在想到底搜索什么。。。然后发现要用的素数很少,不搜素数次数搜什么。。。
    //Serene
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    const long long INF=1e15;
    long long n,ans,t=-1;
    int prime[20]={0,2,3,5,7,11,13,17,19,23,29,31,37};
    
    long long aa;char cc;
    long long read() {
    	aa=0;cc=getchar();
    	while(cc<'0'||cc>'9') cc=getchar();
    	while(cc>='0'&&cc<='9') aa=aa*10+cc-'0',cc=getchar();
    	return aa;
    }
    
    void dfs(long long sum,long long x,int pos,long long maxnum) {
    	if(sum>n) return;
    	if(x>t||(x==t&&sum<ans)) {
    		ans=sum; t=x;
    	}
    	long long xx=prime[pos]*sum,tot=1;
    	while(xx<n&&tot<maxnum) {
    		tot++;
    		dfs(xx,x*tot,pos+1,tot);
    		xx*=prime[pos];
    	}
    }
    
    int main() {
    	n=read();
    	dfs(1,1,1,INF);
    	cout<<ans;
    	return 0;
    }
    

      

    弱者就是会被欺负呀
  • 相关阅读:
    LightProxy修改请求头、cookie
    webpack2项目中引入@vue/composition-api报错Cannot find module
    webpack2项目引入ts后报错@ ./~/vue-style-loader!./~/css-loader!./~/vue-loader/lib/style-compiler?
    mac brew 安装指定版本后 node命令找不到
    python数据类型详解
    更换Linux(CentOS) yum源
    Python读写文件
    Python异常处理try...except、raise
    Python删除空格字符串两端的空格
    python的urllib模块中的方法
  • 原文地址:https://www.cnblogs.com/Serene-shixinyi/p/7563097.html
Copyright © 2020-2023  润新知