#30682: 能不能不要每次都搞我


zaqxswdce26@gmail.com (卡比獸)

學校 : 不指定學校
編號 : 192970
來源 : [49.216.222.215]
最後登入時間 :
2023-10-24 13:17:05
a249. 00679 - Dropping Balls -- UVa679 | From: [220.141.65.125] | 發表日期 : 2022-06-05 23:02

然後Zero Judge超時

 

#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
    int a,b,c,sum,max;
    
    cin>>a;
    while(a--)
    {
        cin>>b>>c;//depth num
        c=c%(int)pow(2,b-1);
        max=pow(2,b-1);
        if(c==0)
            sum=(int)pow(2,b-1)-1;
        else
            sum=0;
        while(c!=1 && c!=0)
        {
            max/=2;
            if(c%2)//left
                c=c/2+1;
            else  //right
            {
                c=c/2;
                sum+=max;
            }
        }
        cout<<sum+(int)pow(2,b-1)<<"\n";
    }

    return 0;
}

 
#31035: Re: 能不能不要每次都搞我


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a249. 00679 - Dropping Balls -- UVa679 | From: [118.160.197.37] | 發表日期 : 2022-07-06 12:07

然後Zero Judge超時

 

#include
#include
using namespace std;
int main(void)
{
    int a,b,c,sum,max;
    
    cin>>a;
    while(a--)
    {
        cin>>b>>c;//depth num
        c=c%(int)pow(2,b-1);
        max=pow(2,b-1);
        if(c==0)
            sum=(int)pow(2,b-1)-1;
        else
            sum=0;
        while(c!=1 && c!=0)
        {
            max/=2;
            if(c%2)//left
                c=c/2+1;
            else  //right
            {
                c=c/2;
                sum+=max;
            }
        }
        cout<    }

    return 0;
}


我改一下就AC (0.8s) 了

  1. IO加速
  2. 不要用pow,改成左移<<
 
ZeroJudge Forum