期望得分:100+100+50=250

实际得分:100+60+50=210

 

T2 二分 估错上界、估错复杂度

 

T1 立方数(cubic)

Time Limit:1000ms   Memory Limit:128MB

 

题目描述

LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数,例如1,8,27就是最小的3个立方数。

现在给定一个数P,LYK想要知道这个数是不是立方数。

当然你有可能随机输出一些莫名其妙的东西来骗分,因此LYK有T次询问~

 

输入格式(cubic.in)

    第一行一个数T,表示有T组数据。

    接下来T行,每行一个数P。

 

输出格式(cubic.out)

输出T行,对于每个数如果是立方数,输出“YES”,否则输出“NO”。

 

输入样例

3

8

27

28

 

输出样例

YES

YES

NO

 

数据范围

对于30%的数据p<=100。

对于60%的数据p<=10^6。

对于100%的数据p<=10^18,T<=100。

 

预处理所有立方数,hash

 

//#include<set>
#include<cstdio>
#include<iostream>

using namespace std;

typedef long long LL;

//#define mod1 9000011
#define mod 3000017

//set<LL>s;
LL has[mod+3];

int bit[21];

void read(LL &x)
{
    x=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
}

void insert(LL x)
{
    LL t=x; int len=0,now=0;
    while(t) 
    {
        now+=t%10*bit[len++];
        while(now>=mod) now-=mod;
        t/=10;
    }
     
    while(has[now]) 
    {
        now++; 
        if(now==mod) now=0;
    }
    has[now]=x;
}

bool find(LL x)
{
    LL t=x; int len=0,now=0;
    while(t) 
    {
        now+=t%10*bit[len++];
        while(now>=mod) now-=mod;
        t/=10;
    }
    while(has[now])
    {
        if(has[now]==x) return true;
        now++; if(now==mod) now=0;
    }
    return false;
}

int main()
{
    freopen("cubic.in","r",stdin);
    freopen("cubic.out","w",stdout);
    bit[0]=1;
    for(int i=1;i<=20;i++) bit[i]=37*bit[i-1]%mod;
    for(int i=1;i<=1000000;i++)//    s.insert(1LL*i*i*i);
        insert(1LL*i*i*i);
    int T;
    scanf("%d",&T);
    LL x;
    while(T--)
    {
        read(x);
        //puts(s.find(x)!=s.end() ? "TES" : "NO" );
        puts(find(x) ? "YES" : "NO");
    }
}
View Code

相关文章: