Bob's Problem

Accepted : 18   Submit : 115
Time Limit : 1000 MS   Memory Limit : 65536 KB 

题目描述

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

输入

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

输出

每行输出一个样例的结果,如果存在,输出“Yes”,否则输出“No”。(引号不用输出)

样例输入

  1. 2
  2. 28
  3. 27

样例输出

  1. Yes
  2. No

哈希

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. using namespace std;
  7. const int INF = ;
  8. int a[];
  9.  
  10. struct node
  11. {
  12. int num;
  13. struct node *next;
  14. };
  15. struct node f[INF];
  16.  
  17. void Insert(int x)
  18. {
  19. struct node *p,*q;
  20. int k;
  21. k=x%INF;
  22. p=&f[k];
  23. while( p!=NULL && p->num!=x)
  24. {
  25. p=p->next;
  26. }
  27. if( p==NULL )
  28. {
  29. q=(struct node*)malloc(sizeof(struct node));
  30. q->next=f[k].next;
  31. q->num=x;
  32. f[k].next=q;
  33. }
  34. }
  35. bool found(int x)
  36. {
  37. int k;
  38. struct node *p;
  39. k=x%INF;
  40. p=&f[k];
  41. while( p!=NULL && p->num!=x)
  42. {
  43. p=p->next;
  44. }
  45. if( p==NULL)
  46. return false;
  47. if( p->num==x)
  48. return true;
  49. }
  50. void prepare()
  51. {
  52. int i,j;
  53. for(i=;i<=;i++)
  54. a[i]=i*i*i;
  55.  
  56. for(i=;i<INF;i++)
  57. {
  58. f[i].num=;
  59. f[i].next=NULL;
  60. }
  61. for(i=;i<=;i++)
  62. for(j=i;j<=;j++)
  63. {
  64. Insert(a[i]+a[j]);
  65. }
  66. }
  67. int main()
  68. {
  69. int n,i,x;
  70. prepare();
  71. while(scanf("%d",&n)>)
  72. {
  73. for(i=;i<=n;i++)
  74. {
  75. scanf("%d",&x);
  76. if( found(x)==true )
  77. printf("Yes\n");
  78. else printf("No\n");
  79. }
  80. }
  81. return ;
  82. }

set

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<set>
  6. #include<algorithm>
  7. using namespace std;
  8.  
  9. int a[];
  10. set<int> Q;
  11. void prepare()
  12. {
  13. int i,j;
  14. for(i=;i<=;i++)
  15. a[i]=i*i*i;
  16. Q.clear();
  17. for(i=;i<=;i++)
  18. for(j=i;j<=;j++)
  19. Q.insert(a[i]+a[j]);
  20. }
  21. int main()
  22. {
  23. int T,n;
  24. prepare();
  25. scanf("%d",&T);
  26. while(T--)
  27. {
  28. scanf("%d",&n);
  29. int flag=Q.count(n);
  30. if(flag==)printf("No\n");
  31. else printf("Yes\n");
  32. }
  33. return ;
  34. }

湘潭校赛 Bob's Problem的更多相关文章

  1. 湘潭校赛 Hard Wuxing

    Hard Wuxing Accepted : 13   Submit : 166 Time Limit : 1000 MS   Memory Limit : 65536 KB 题目描述 “五行”是中国 ...

  2. 湘潭校赛 Easy Wuxing

    Easy Wuxing Accepted : 25   Submit : 124 Time Limit : 1000 MS   Memory Limit : 65536 KB 题目描述 “五行”是中国 ...

  3. 2019湘潭校赛 G(并查集)

    要点 题目传送 题目本质是每个点必属于两个集合中的一个,伴随的性质是:如果一个人说别人true,则他们一定属于同一阵营:如果说别人fake,一定不属于同一阵营. 每个点拆为\(i\)和\(i + n\ ...

  4. 2019湘潭校赛 H(dp)

    题目传送 dp是常规的:\(m^2\)的预处理:把位置存进vector然后\(O(1)\)算出想要的:WA点:要注意特意设置一下val[i][v.size()]=0,即全天都放鸽子则花费时间为0. # ...

  5. 2019湘潭校赛 E(答案区间维护)

    题目传送 思路是始终维护西瓜数量的区间,即L代表目前可以达到的最少的,R是最多的,然后判断一下. #include <bits/stdc++.h> using namespace std; ...

  6. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  7. SCNU省选校赛第二场B题题解

    今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...

  8. 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】

    链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  9. 校赛F 比比谁更快(线段树)

    http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...

随机推荐

  1. python del 方法的使用

    在Python 的自带函数中 del 函数是一个非常特殊但是又非常使用的函数 my_list = [1,2,3] my_dict = {"name":"lowman&qu ...

  2. JS弹出对话框函数alert(),confirm(),prompt()

    1,警告消息框alert() alert 方法有一个参数,即希望对用户显示的文本字符串.该字符串不是 HTML 格式.该消息框提供了一个“确定”按钮让用户关闭该消息框,并且该消息框是模式对话框,也就是 ...

  3. WebBench源码分析

    源码分析共享地址:https://github.com/fivezh/WebBench 下载源码后编译源程序后即可执行: sudo make clean sudo make & make in ...

  4. MVC4删除 pages引发的异常 System.Web.Optimization找不到引用

    在MVC4的开发中,如果创建的项目为空MVC项目,那么在App_Start目录下没有BundleConfig.cs项的内容,在手动添加时在整个库中都找不到:System.Web.Optimizatio ...

  5. 在Linux CentOS上部署Asp.Net Core项目(Tengine、Asp.Net Core、Centos、MySql)

    一.前言 1.简单记录一下Linux CentOS 7中安装与配置Tengine的详细步骤. 2.简单比较一下Tengine 和Nginx 3.搭建Asp.net Core和部署 Web程序 4.总结 ...

  6. RDLC_部署到不同的浏览器

    首先我用的是vs2015 的reportview插件 在数据库中应该配置报表的服务器地址,在项目中添加ReportViewer 插件,单独用一个页面显示接收报表 <form id="f ...

  7. Linux服务器快速安装可视化桌面且可以远程RDP远程连接

    我们很多网友在选择Linux服务器的时候并不是用来做网站的,有些是需要用到远程桌面安装软件或者是其他用途.但是我们知道大部分海外主机商是只有LINUX系统且没有可视化桌面,当然也有一些商家是支持安装G ...

  8. 51单片机SRF寄存器

    1.21个寄存器介绍        51系列单片机内部主要有四大功能模块,分别是I/O口模块.中断模块.定时器模块和串口通信模块(串行I/O口),如其结构和功能如下图: 图1 51单片机结构和功能图 ...

  9. (转)MySQL日志管理

    MySQL 服务器上一共有六种日志:错误日志,查询日志,慢查询日志,二进制日志,事务日志,中继日志. 原文:https://segmentfault.com/a/1190000003072237 一 ...

  10. Annotate类

    在Annotate类中有个Annotator接口,定义如下: /** A client that has annotations to add registers an annotator, * th ...