zoukankan      html  css  js  c++  java
  • Codeforces Round #112 (Div. 2) & #125 (Div. 2)总结(不要用pow&log!!!)

    1.遇到需要用大数处理的问题,一定要先去思考能避开大数的程序,不要上来就用c++大数模板或java大数函数,前者敲起来繁琐,后者效率太低。

    #include <stdio.h>
    #include <iostream>
    using namespace std;
    int main()
    {
        long long k,b,n,t,z;
        while(cin >> k >> b >> n >>t){
            long long x=1;
            int cou=0;
            while(x<=t && cou<=n){
                x=k*x+b;
                cou++;
            }
            cout << n-cou+1 <<endl;
        }
        return 0;
    }

    2.pow,log这种处理double的东西尽量不要和整型运算混用,会造成精度缺失以导致wa的。

    3.遇到不等关系,为了防止精度缺失,最好还是一步一步踏踏实实地运算。

    #include <iostream>
    #include <math.h>
    using namespace std;
    #include <stdio.h>
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("WA.txt","w",stdout);
        int n;
        double k;
        while(cin >> n >>k){
            int l=1,r=n;
            int mid=-1;
            while(l<r){
                //cout << l <<" "<< r <<endl;
                mid=(l+r)/2;
                long long p=0;
                long long kk=1;
                while(mid>=kk){
                    kk*=k;
                    p++;
                }
                long long sum=0;
                for(int i=0;i<=p;i++){
                    kk=1;
                    for(int j=0;j<i;j++){
                        kk*=k;
                    }
                    sum+=mid/kk;
                }
                if(sum>=n) r=mid;
                else l=mid+1;
            }
            cout << r <<endl;
        }
        return 0;
    }
  • 相关阅读:
    泛型
    内部类 及 匿名内部类
    BigDecimal
    JodaTime简介
    Java中IO流
    Spring的ApplicationEvent的使用
    swagger文档使用(springboot项目)
    http连接过程遇到的各种性能瓶颈
    http网络连接过程
    python中的TypeError: 'NavigableString' object is not callable错误
  • 原文地址:https://www.cnblogs.com/markliu/p/2624414.html
Copyright © 2011-2022 走看看