湘潭校赛 Bob's Problem
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”。(引号不用输出) 样例输入
样例输出
|
哈希
- #include<iostream>
- #include<stdio.h>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- using namespace std;
- const int INF = ;
- int a[];
- struct node
- {
- int num;
- struct node *next;
- };
- struct node f[INF];
- void Insert(int x)
- {
- struct node *p,*q;
- int k;
- k=x%INF;
- p=&f[k];
- while( p!=NULL && p->num!=x)
- {
- p=p->next;
- }
- if( p==NULL )
- {
- q=(struct node*)malloc(sizeof(struct node));
- q->next=f[k].next;
- q->num=x;
- f[k].next=q;
- }
- }
- bool found(int x)
- {
- int k;
- struct node *p;
- k=x%INF;
- p=&f[k];
- while( p!=NULL && p->num!=x)
- {
- p=p->next;
- }
- if( p==NULL)
- return false;
- if( p->num==x)
- return true;
- }
- void prepare()
- {
- int i,j;
- for(i=;i<=;i++)
- a[i]=i*i*i;
- for(i=;i<INF;i++)
- {
- f[i].num=;
- f[i].next=NULL;
- }
- for(i=;i<=;i++)
- for(j=i;j<=;j++)
- {
- Insert(a[i]+a[j]);
- }
- }
- int main()
- {
- int n,i,x;
- prepare();
- while(scanf("%d",&n)>)
- {
- for(i=;i<=n;i++)
- {
- scanf("%d",&x);
- if( found(x)==true )
- printf("Yes\n");
- else printf("No\n");
- }
- }
- return ;
- }
set
- #include<iostream>
- #include<stdio.h>
- #include<cstring>
- #include<cstdlib>
- #include<set>
- #include<algorithm>
- using namespace std;
- int a[];
- set<int> Q;
- void prepare()
- {
- int i,j;
- for(i=;i<=;i++)
- a[i]=i*i*i;
- Q.clear();
- for(i=;i<=;i++)
- for(j=i;j<=;j++)
- Q.insert(a[i]+a[j]);
- }
- int main()
- {
- int T,n;
- prepare();
- scanf("%d",&T);
- while(T--)
- {
- scanf("%d",&n);
- int flag=Q.count(n);
- if(flag==)printf("No\n");
- else printf("Yes\n");
- }
- return ;
- }
湘潭校赛 Bob's Problem的更多相关文章
- 湘潭校赛 Hard Wuxing
Hard Wuxing Accepted : 13 Submit : 166 Time Limit : 1000 MS Memory Limit : 65536 KB 题目描述 “五行”是中国 ...
- 湘潭校赛 Easy Wuxing
Easy Wuxing Accepted : 25 Submit : 124 Time Limit : 1000 MS Memory Limit : 65536 KB 题目描述 “五行”是中国 ...
- 2019湘潭校赛 G(并查集)
要点 题目传送 题目本质是每个点必属于两个集合中的一个,伴随的性质是:如果一个人说别人true,则他们一定属于同一阵营:如果说别人fake,一定不属于同一阵营. 每个点拆为\(i\)和\(i + n\ ...
- 2019湘潭校赛 H(dp)
题目传送 dp是常规的:\(m^2\)的预处理:把位置存进vector然后\(O(1)\)算出想要的:WA点:要注意特意设置一下val[i][v.size()]=0,即全天都放鸽子则花费时间为0. # ...
- 2019湘潭校赛 E(答案区间维护)
题目传送 思路是始终维护西瓜数量的区间,即L代表目前可以达到的最少的,R是最多的,然后判断一下. #include <bits/stdc++.h> using namespace std; ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- SCNU省选校赛第二场B题题解
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
- 牛客网多校赛第9场 E-Music Game【概率期望】【逆元】
链接:https://www.nowcoder.com/acm/contest/147/E 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 校赛F 比比谁更快(线段树)
http://acm.cug.edu.cn/JudgeOnline/problem.php?cid=1153&pid=5 题意:给你一个字符串,各两个操作: ch=0,[l,r]降序 ch=1 ...
随机推荐
- python del 方法的使用
在Python 的自带函数中 del 函数是一个非常特殊但是又非常使用的函数 my_list = [1,2,3] my_dict = {"name":"lowman&qu ...
- JS弹出对话框函数alert(),confirm(),prompt()
1,警告消息框alert() alert 方法有一个参数,即希望对用户显示的文本字符串.该字符串不是 HTML 格式.该消息框提供了一个“确定”按钮让用户关闭该消息框,并且该消息框是模式对话框,也就是 ...
- WebBench源码分析
源码分析共享地址:https://github.com/fivezh/WebBench 下载源码后编译源程序后即可执行: sudo make clean sudo make & make in ...
- MVC4删除 pages引发的异常 System.Web.Optimization找不到引用
在MVC4的开发中,如果创建的项目为空MVC项目,那么在App_Start目录下没有BundleConfig.cs项的内容,在手动添加时在整个库中都找不到:System.Web.Optimizatio ...
- 在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.总结 ...
- RDLC_部署到不同的浏览器
首先我用的是vs2015 的reportview插件 在数据库中应该配置报表的服务器地址,在项目中添加ReportViewer 插件,单独用一个页面显示接收报表 <form id="f ...
- Linux服务器快速安装可视化桌面且可以远程RDP远程连接
我们很多网友在选择Linux服务器的时候并不是用来做网站的,有些是需要用到远程桌面安装软件或者是其他用途.但是我们知道大部分海外主机商是只有LINUX系统且没有可视化桌面,当然也有一些商家是支持安装G ...
- 51单片机SRF寄存器
1.21个寄存器介绍 51系列单片机内部主要有四大功能模块,分别是I/O口模块.中断模块.定时器模块和串口通信模块(串行I/O口),如其结构和功能如下图: 图1 51单片机结构和功能图 ...
- (转)MySQL日志管理
MySQL 服务器上一共有六种日志:错误日志,查询日志,慢查询日志,二进制日志,事务日志,中继日志. 原文:https://segmentfault.com/a/1190000003072237 一 ...
- Annotate类
在Annotate类中有个Annotator接口,定义如下: /** A client that has annotations to add registers an annotator, * th ...