巧题 | 北邮OJ | 130. 非平方等式
https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/130/
线性搜索,超时代码
/*
USER_ID: test#shizhuxiniubi
PROBLEM: 130
SUBMISSION_TIME: 2019-02-04 08:31:57
*/
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 100
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;using namespace std;
typedef long long ll;
const double pi=acos(-1);ll s(int x){ll ans=0;while(x){ans+=x%10;x/=10;}return ans;
}int main()
{// freopen("./in","r",stdin);ll n,x;cin>>n;for(x=1;1;x++){if(x*x>n){puts("-1");break;}if(x*x+s(x)*x==n){printf("%lld\n",x);break;}}return 0;
}
缩小搜索范围,AC代码
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 100
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;using namespace std;
typedef long long ll;
const double pi=acos(-1);ll s(int x){ll ans=0;while(x){ans+=x%10;x/=10;}return ans;
}int main()
{// freopen("./in","r",stdin);ll n,x,ans=-1,k;cin>>n;for(x=(ll)sqrt(n)+1,k=0;x>=0 && k<18*9;x--,k++){if(x*x+x*s(x)==n){ans=x;break;}}cout<<ans<<endl;return 0;
}
巧题 | 北邮OJ | 130. 非平方等式相关推荐
- 北邮oj题库刷题计划(更新ing)
北邮oj题库刷题计划(更新ing) 83. A + B Problem 84 Single Number 85. Three Points On A Line 120 日期 121 最值问题 122 ...
- 北邮OJ 141 虚数
北邮OJ 虚数 #include <bits/stdc++.h> using namespace std; typedef struct fushu{int x; //实部 int y; ...
- 校外如何登陆北邮oj
由于北邮oj不对外开放,准备复试的我需要进入北邮oj:其他小朋友也有这个想法.故写此博客. 先找北邮土著借北邮账号,包括一些认识的同学,直系学长学姐,他们都很乐意帮助的~ 下面是校外进北邮校内网的方法 ...
- 北邮OJ 102. 最远距离 北邮2012网研院复试上机题
102. 最远距离 时间限制1000 ms 内存限制 65536 KB 题目描述 正义的伙伴褋祈和葬仪社的机器人Fuyuneru正在被邪恶的GHQ部队追杀.眼看着快要逃不掉了,祈就把重 ...
- 北邮OJ 1022. 16校赛-Saber's Board
时间限制 5000 ms 内存限制 65536 KB 题目描述 In a parallel universe, Saber has won the champion of every kind of ...
- 北邮OJ 1021. 16校赛-Stone Game
时间限制 4000 ms 内存限制 65536 KB 题目描述 Alice and Bob are old friends in game theory. This afternoon they me ...
- 北邮OJ 980. 16校赛-R_clover's Challenge
时间限制 2000 ms 内存限制 65536 KB 题目描述 R_clover wants to challenge Mengmengda_wsw's math,so he give her a f ...
- 北邮OJ 884. 16校赛-Average Modulo
时间限制 5000 ms 内存限制 65536 KB 题目描述 We define function g on an array as: g([a0,a1,⋯,an−1])=(Σn−1l=0al) m ...
- 北邮oj 108 虚数
108. 虚数 时间限制 1000 ms 内存限制 65536 KB 题目描述 给你一个复数集合{Aj+i*Bj},保证Aj和Bj都是整数,初始为空集. 每次会给你如下两种操作中的一种: 1.&quo ...
最新文章
- python使用matplotlib中的errorbar函数可视化误差条、并自定义数据点标记、数据点大小、数据点颜色、数据点边缘颜色、误差棒颜色、误差棒线条宽度、误差棒边界线长度、误差棒边界线厚度等
- 深度学习在CTR预估的应用
- 图形处理(二)固定边界参数化
- Geoserver怎样设置地图不同路线显示不用颜色样式(同一个图层组设置多个图层不同样式)
- Struts2s:select/s:select
- 某娱乐资源网同款网站源码
- Android Spinnert的使用
- 【英语学习】【医学】【解剖学】Atlas of Human Anatomy (6e) 的目录
- Layer2匿名交易协议ZKCHAOS与跨链资产桥ChainSwap合作促进跨链隐私保护
- android开发微博前的包准备,新浪微博开发之前期准备篇
- Windows/Ubuntu 使用小技巧记录
- mysql查询名字重复四次以上的人名_怎么查询数据库中重复字段的名字
- 王道训练营3月18日
- 联想小新系列笔记本 黑苹果BIOS配置
- yum 报错:Another app is currently holding the yum lock; waiting for it to exit......
- 怎么将PDF转换成jpg图片?免费方法了解一下
- 利用U盘重新安装XP系统
- 没有换行又很多很多行的代码,如何快捷换行?
- linux自动获取ipv6,IPv6系列-详解自动分配IPv6地址
- 我是一个硬盘(转自北大未名)