题目链接:http://codeforces.com/problemset/problem/460/B

题目意思:给出a, b, c三个数,要你找出所有在 1 ≤ x ≤ 1e9 范围内满足 x = b·s(x)a +  这条等式的x的个数,并输出相应的 x 具体是多少。

不看tutorial 都不知道,原来枚举的方向错了,人家是枚举1~81 的情况,我就是枚举1~1e9, = =。。。直接暴力即可,有个比较要注意的地方,算方程右边的时候有可能超过int,需要用long long 或 __int64 保存。

(1)long long 版

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e6; // 不知道符合的x有多少个,尽量开大一点吧
const int maxx = 1e9;
const int minx = ; typedef long long LL;
int ans[maxn];
LL tx; int main()
{
int a, b, c;
while (scanf("%d%d%d", &a, &b, &c) != EOF)
{
int cnt = ;
for (int i = ; i <= ; i++) // 枚举1~999999999每位数字和
{
int sx = i;
int p = i;
for (int j = ; j < a; j++)
sx *= p;
tx = (LL)sx*b + (LL)c;
if (tx > maxx || tx < minx)
continue;
int x = sx*b + c;
int tot = ;
while (x)
{
tot += x%;
x /= ;
}
if (tot == i)
ans[cnt++] = sx*b + c;
}
}
printf("%d\n", cnt);
for (int i = ; i < cnt; i++)
printf("%d ", ans[i]);
}
return ;
}

(2) __int64 版本

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e6;
const int maxx = 1e9;
const int minx = ; int ans[maxn];
__int64 tx, a, b, c; int main()
{
while (scanf("%I64d%I64d%I64d", &a, &b, &c) != EOF)
{
int cnt = ;
for (int i = ; i <= ; i++) // 枚举1~999999999每位数字和
{
__int64 sx = i;
__int64 p = i;
for (int j = ; j < a; j++)
sx *= p;
tx = sx*b + c;
if (tx > maxx || tx < minx)
continue;
__int64 x = sx*b + c;
int tot = ;
while (x)
{
tot += x%;
x /= ;
}
if (tot == i)
ans[cnt++] = sx*b + c;
}
printf("%d\n", cnt);
for (int i = ; i < cnt; i++)
printf("%d ", ans[i]);
}
return ;
}

总结:long long 写起来好像比 __int64 简单一些啦

这个是参考作者写的,本人更喜欢作者的写法,每个函数有各自的功能,而且比较清晰,很奇怪的是,用codeblocks 检验第 三 组 数据 2 2 1 的时候,我的电脑一直输出0,用custom test 可以得出正确结果。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std; typedef long long ll;
vector<ll> ans;
ll a, b, c; ll S(ll p, ll a)
{
ll s = ;
for (int i = ; i <= a; i++)
s *= p;
return s;
} ll Digit(ll x)
{
ll wei = ;
while (x)
{
wei += x % ;
x /= ;
}
return wei;
} int main()
{
int len = ;
while (scanf("%lld%lld%lld", &a, &b, &c) != EOF)
{
for (ll i = ; i < len; i++)
ans.clear();
for (ll i = ; i <= ; i++)
{
ll x = b*S(i, a) + c;
if (x < 1e9 && Digit(x) == i)
ans.push_back(x);
}
printf("%d\n", ans.size());
for (int i = ; i < ans.size(); i++)
printf("%lld ", ans[i]);
len = ans.size();
}
return ;
}

codeforces 460B Little Dima and Equation 解题报告的更多相关文章

  1. 【LeetCode】640. Solve the Equation 解题报告(Python)

    [LeetCode]640. Solve the Equation 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: ht ...

  2. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  3. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  4. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  5. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  6. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  7. codeforces 505A. Mr. Kitayuta's Gift 解题报告

    题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...

  8. codeforces 499A.Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...

  9. ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

    Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

随机推荐

  1. 洛谷 P1503鬼子进村

    题目背景 小卡正在新家的客厅中看电视.电视里正在播放放了千八百次依旧重播的<亮剑>,剧中李云龙带领的独立团在一个县城遇到了一个鬼子小队,于是独立团与鬼子展开游击战. 题目描述 描述 县城里 ...

  2. MySQL、Hive以及MySQL Connector/J安装过程

    MySQL安装 ①官网下载mysql-server(yum安装) wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch. ...

  3. WIP - 离散任务点击组件-错误:LOCATOR.CONTROL 的变元无效:ORG_LOCATOR_CONTROL=''

    Getting Error "Invalid Argument to LOCATOR.CONTROL: ORG_LOCATOR_CONTROL='' in Material Requirem ...

  4. IT部门的KPI该如何制定?

    导语:信息化成本.系统开机率.网路不断线时数.系统运行速度.软件开发时间.用户问题处理反应时间.系统品质.用户满意度--哪些指标是可被管理的,能指引IT部门成为一个有价值的.为企业带来效益的部门呢? ...

  5. golang几种post请求方式

    get请求 get请求可以直接http.Get方法,非常简单. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 func httpGet() {     resp, err := h ...

  6. Web常见安全漏洞原理及防范-学习笔记

    公司在i春秋上面报的一个课程.http://www.ichunqiu.com/course/55885,视频学习. OWASP (Open Web Application Secutiry Proje ...

  7. [CSS3] Define Form Element States with CSS Form Pseudo Classes

    Using just semantic CSS Pseudo-Classes you can help define important states for form elements that e ...

  8. PS 如何使用液化工具给人物减肥

    进入"液化", 有个收缩按钮, 可以选择范围大小, 想瘦哪里, 瘦多少都OK   最终效果图     1.打开原图,进入通道面板,选择菜单图像计算,计算红色通道,保留人物见图.   ...

  9. JAVA_MyEclipse常见配置NETGEAR路由器如何设置

    1 把宽带网线接到路由器的Internet口,然后用一个网线连接PC和路由器的任意端口(1,2,3,4一般四个),如下图所示 2 在浏览器地址栏中输入下面的网址,中途会弹出对话框询问账号密码,默认的账 ...

  10. Type cannot use 'try' with exceptions disabled

    cannot use ‘throw’ with exceptions disabled 在为 DragonBonesCPP/refactoring 的 cocos2d-x-3.2 demo 增加 An ...