Bob's Problem

Accepted : 114   Submit : 589
Time Limit : 1000 MS   Memory Limit : 65536 KB

题目描写叙述

Bob今天碰到一个问题。他想知道x3+y3 = c 是否存在正整数解?

输入

第一行是一个整数K(K≤20000),表示例子的个数。 以后每行一个整数c(2≤c≤109)

输出

每行输出一个例子的结果。假设存在。输出“Yes”,否则输出“No”。(引號不用输出)

例子输入

2
28
27

例子输出

Yes
No

Source

XTU OnlineJudge

分析:暴力+二分。

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; int ans[1000010]; int main()
{
int len=0;
int n,m,l,r;
bool flag;
memset(ans,false ,sizeof(ans));
for(int i=1;i<=1000;i++)
{
for(int j=i;j*j*j+i*i*i<=1000000000;j++)
{
ans[len++]=j*j*j+i*i*i;
}
}
sort(ans,ans+len);
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
l=0,r=len-1;
flag=false ;
while(l<=r)
{
int mid=(l+r)/2;
if(ans[mid]==m)
{
flag=true ;
break;
}
if(ans[mid]<m)
l=mid+1;
else r=mid-1;
}
if(flag) printf("Yes\n");
else printf("No\n");
}
}

湘潭大学1185 Bob&#39;s Problem的更多相关文章

  1. hdu----(5055)Bob and math problem(贪心)

    Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. HDU 5055 Bob and math problem(结构体)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...

  3. UVA 1484 - Alice and Bob&#39;s Trip(树形DP)

    题目链接:1484 - Alice and Bob's Trip 题意:BOB和ALICE这对狗男女在一颗树上走,BOB先走,BOB要尽量使得总路径权和大,ALICE要小,可是有个条件,就是路径权值总 ...

  4. UVA - 10239 The Book-shelver&#39;s Problem

    Description Problem D The Book-shelver's Problem Input: standard input Output: standard output Time ...

  5. codeforces 459D - Pashmak and Parmida&#39;s problem【离散化+处理+逆序对】

    题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...

  6. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

  7. UVA 10026 Shoemaker&#39;s Problem

    Shoemaker's Problem Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can w ...

  8. Hotaru&#39;s problem(hdu5371+Manacher)多校7

    Hotaru's problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  9. 【HDOJ 5371】 Hotaru&#39;s problem

    [HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...

随机推荐

  1. CUDA C Best Practices Guide 在线教程学习笔记 Part 2

    10. 执行配置优化 ● 一个 SM中,占用率 = 活动线程束的数量 / 最大可能活动线程束的数量.后者保存在设备属性的  maxThreadsPerMultiProcessor  分量中(GTX10 ...

  2. 通用的contain函数

    用来检测节点所属关系:document.documentElement.contains(document.body) function contains(refNode, otherNode) {i ...

  3. Python中的输出

    1.Python的输出语句 Python输出语句是print,但是python2.x与3.x又有点区别.python2.x输出 print "xxx"能成功执行,而3.x不行,所以 ...

  4. css伪类的说明以及使用(css事件)

    CSS伪类的使用(css事件) 转载请注明源地址:http://www.cnblogs.com/funnyzpc/p/7670959.html 之前有开发开发App的时候,有同事问我那个列表的条目按下 ...

  5. java二维码生成

    import java.io.File; import java.nio.file.Path; import java.util.HashMap; import com.google.zxing.Ba ...

  6. Dapper-继续

    好久没有来博客园了,最近刚好有点时间晚上,继续完善之前的orm orm自己用的比较多的还是EF,linq写着真的是很方便,但是EF最让人头疼的地方还是每个表都需要建立mapping. 这个是相当的烦恼 ...

  7. 【2】构建一个SSM项目结构

    初步思考一下这个项目的结构,由于是给一个比较老的公司做这个外包项目,服务器是搭建在windows操作系统上的Tomcat6.0,系统的JDK版本也是JDK1.6,都是比较旧. 数据库方面有专人负责,所 ...

  8. Python的__main__.py用法

    [背景] 在看flower的时候看到__main__.py文件,不知道具体做什么用? 故先进行测试看看. [测试代码] 测试代码目录结构如下: . `-- test |-- __init__.py | ...

  9. tornado+WSGI+Apache

    1.原理 2.安装mod_wsgi http://pan.baidu.com/s/1sjsccWH configure的时候会找对应的python脚本,默认是/usr/bin/python 生成mod ...

  10. SpringMVC---CookieValue

    配置文件承接一二章 @CookieValue的作用 用来获取Cookie中的值 1.value:参数名称 2.required:是否必须 3.defaultValue:默认值 原网址:https:// ...