zoukankan      html  css  js  c++  java
  • Ad Hoc类问题

    __________________________________

    Ad Hoc类问题的方法:
    (1)机理分析法。分析题目描述,推出算法。

    (2)统计分析法。追寻最终的数学模型。

     Problem 1:

    起始的奇迹之年是1960年。

     

    第n年的位数k=2^(2+(y-1960)/10),能放在k位中最大的无符号整数是(2^k)-1, 那么我们就引入了对数的运算:

    --------------https://vjudge.net/contest/317081#problem/A

    code:

    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int year;
        int endflag;
        int n;
        double sum;
        while(scanf("%d",&year),year)
        {
            endflag=1<<((year-1960)/10+2);// 1<<a==pow(2,a)
            
    	n=2;
            sum=0;
            while(sum<=endflag)
            {
                sum+=log(n)/log(2);//log2(n)!
                n++;
            }
            printf("%d
    ",n-2);
        }
        return 0;
    }
    

    Problem 2:

    https://vjudge.net/contest/317081#problem/C

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int t,d,m,n,min_,max_;
    int main()
    {
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d%d",&m,&n);
    		min_=max_=0;//双双赋值! 
    		while(n--)
    		{
    			scanf("%d",&d);
    			min_=max(min_,min(d,m-d));
    			max_=max(max_,max(d,m-d));
    		}
    		printf("%d %d
    ",min_,max_);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    位置定位 api
    代理相关
    手机网页 右边的空白区
    sip介绍
    测试浏览器对html5支持
    sencha touch
    PC上的手机模拟器大全(安卓/苹果/黑莓/塞班/微软)
    测试视频
    android 环境配置 与 运行错误
    android 一年过期
  • 原文地址:https://www.cnblogs.com/dragondragon/p/11297602.html
Copyright © 2011-2022 走看看