湘潭大学1185 Bob's Problem
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 例子输出Yes SourceXTU 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's Problem的更多相关文章
- hdu----(5055)Bob and math problem(贪心)
Bob and math problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 5055 Bob and math problem(结构体)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...
- UVA 1484 - Alice and Bob's Trip(树形DP)
题目链接:1484 - Alice and Bob's Trip 题意:BOB和ALICE这对狗男女在一颗树上走,BOB先走,BOB要尽量使得总路径权和大,ALICE要小,可是有个条件,就是路径权值总 ...
- UVA - 10239 The Book-shelver's Problem
Description Problem D The Book-shelver's Problem Input: standard input Output: standard output Time ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
- UVA 10026 Shoemaker's Problem
Shoemaker's Problem Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can w ...
- Hotaru's problem(hdu5371+Manacher)多校7
Hotaru's problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 【HDOJ 5371】 Hotaru's problem
[HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...
随机推荐
- transform的影响
http://www.cnblogs.com/chuangweili/p/5167986.html transform 各种影响 1.提升元素的z-index层级,下面这个例子会让前面的图片显示在上面 ...
- Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0,"解决办法
这是因为先安装了 .NET Framework 4,随后启用了 .NET Framework 3.5 WCF HTTP 激活,则会发生此错误. 只需要已管理员用户在cmd中运行aspnet_regii ...
- C++雾中风景2:struct还是class?
之前因为都在忙着毕业的开题答辩与投稿论文的事宜,一直没有时间更新这个系列的文章.师弟看了上一篇雾中风景的文章,希望我继续把这个系列的文章写下去.坦白说,C++的特性很多,这也不是教学指南的文章,我会选 ...
- CTF线下攻防赛
SSH登陆 两三个人进行分工,一个粗略的看下web,有登陆口的话,就需要修改密码,将情况反馈给队友,让登陆ssh的小伙伴进行密码的修改,改成炒鸡复杂.然后将Web目录下载下来,上WAF.文件监控.端口 ...
- Python 集合整理
- SpringMVC 快速入门
SpringMVC 快速入门 SpringMVC 简介 SpringMVC是 Spring为展示层提供的基于Web MVC设计模式的请求驱动类型的轻量级Web框架,它的功能和Struts2一样.但比S ...
- iOS swift的xcworkspace多项目管理(架构思想)
iOS swift的xcworkspace多项目管理(架构思想) 技术说明: 今天在这里分享 swift下的 xcworkspace多项目管理(架构思想),能为我们在开发中带来哪些便捷?能为我们对整 ...
- 实现基于tomcat集群会话保持
1.实验环境 我们需要准备两台虚拟机,把这两台虚拟机组成集群,实现会话保持. 2.配置server1 2.1 修改nginx配置文件 [root@server1 ~]# vim /etc/nginx/ ...
- Android APK反编译 apktool使用教程
2017年棋牌游戏突然就火了,正所谓春江水暖鸭先知本猿处在软件行业中就能清晰的感受到市场的变化,最近老家那边也是玩的风生水起,于是最近闲暇时光想到反编译下这些棋牌软件,看看代码实现的思路 (注:反编译 ...
- ajax实现用户名校验的传统和jquery的$.post方式
第一种:传统的ajax异步请求,后台代码以及效果在最下边 首先我们在eclipse中创建一个注册页面regist.jsp,创建一个form表单,注意,由于我们只是实现用户名校验的效果,下边红色部门是我 ...