uva11549 Floyd判圈法
题意:
给两个数n, k,每次将k平方取k的前n位,问所有出现过的数的最大值
原来这就是floyd判圈法。。
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string> template<typename Q> Q read(Q& x) {
static char c;
static bool f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x; return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} typedef long long LL; int next(int n, int x) {
LL x2 = (LL) x * x;
int len = ;
for(LL t = x2; t; t /= ) len++;
if(len > n) for(int t = len - n; t--; x2 /= );
return x2;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int T = read<int>();
while(T--) {
int n = read<int>(), k = read<int>();
int ans = k, k1 = k, k2 = k;
do {
k1 = next(n, k1);
k2 = next(n, k2); ans = std::max(ans, k2);
k2 = next(n, k2); ans = std::max(ans, k2);
}while(k1 != k2);
printf("%d\n", ans);
} return ;
}
uva11549 Floyd判圈法的更多相关文章
- UVA-11549(floyd判圈算法)
题意: 给一个整数k,每次平方后只能显示结果的前n位,问在这个过程中能得到的最大的数是多少; 思路: floyd判圈算法;它的正确性建立在这得到的这些数是有限的,所以一定是一个循环,在这个循环的圈里面 ...
- Floyd判圈法
---恢复内容开始--- http://blog.csdn.net/ruoruo_cheng/article/details/53100656 ---恢复内容结束---
- UVa 1594 (Floyd判圈) Ducci Sequence
大白书上P42那个计算器的题目就用到了这个办法,Floyd判圈法. 当然,用STL里的map也是可以的. #include <cstdio> #include <cmath> ...
- UVa11549计算器谜题[floyd判圈]
题意: 有个老式计算器,每次只能记住一个数字的前n位.现在输入一个整数k,然后反复平方,一直做下去,能得到的最大数是多少.例如,n=1,k=6,那么一次显示:6,3,9,1... 白书上的题 set, ...
- UVa 11549 计算器谜题(Floyd判圈算法)
https://vjudge.net/problem/UVA-11549 题意: 有一个老式计算器,只能显示n位数字,输入一个整数k,然后反复平方,如果溢出的话,计算器会显示结果的最高n位.如果一直这 ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- UVA 11549 CALCULATOR CONUNDRUM(Floyd判圈算法)
CALCULATOR CONUNDRUM Alice got a hold of an old calculator that can display n digits. She was bore ...
- UVA 11549 Calculator Conundrum (Floyd判圈算法)
题意:有个老式计算器,每次只能记住一个数字的前n位.现在输入一个整数k,然后反复平方,一直做下去,能得到的最大数是多少.例如,n=1,k=6,那么一次显示:6,3,9,1... 思路:这个题一定会出现 ...
- leetcode202(Floyd判圈算法(龟兔赛跑算法))
Write an algorithm to determine if a number is "happy". 写出一个算法确定一个数是不是快乐数. A happy number ...
随机推荐
- 【工具篇】notepad++
一直都是使用notepad++来写程序,感觉比UE好用多了,没有UE那么重.前段时间网上还做了一个调查,notepad++在国外使用排行还是非常高的,在国内也是很流行.以下记录一些比较实用的技巧. 一 ...
- String,StringBuffer,StringBuilder的简单比较
原文:http://blog.csdn.net/rmn190/article/details/1492013 String 字符串常量StringBuffer 字符串变量(线程安全)StringB ...
- php和js根据子网掩码和ip计算子网
php $ip = '192.168.6.1'; $mask = '255.255.2.0'; $sub_net = array();//子网 $ip_explode = explode('.', $ ...
- 怎样制作PHP验证码?
<?php /** *制作验证码 *1.启动session *2.设定标头 *3.创建画布 *4.创建颜色 *5.创建随机数并放到画布上 *6.将得到的若干随机数放入session中 *7.添加 ...
- PHP 面向对对象基础(接口,类)
介绍PHP面向对象的基础知识 1. 接口的定义interface ,类定义class,类支持abstract和final修饰符,abstract修饰为抽象类,抽象类 不支持直接实例化,final修饰的 ...
- IS about 64bit system
This function supports the 64-bit parts of the registry by using the REGDB_OPTION_WOW64_64KEY option ...
- 小爬虫。爬取网站多页的通知标题并存取在txt文档里。
爬取网页中通知标题的内容展示: this is 1 page!<精算学综合>科目考试参考大纲2016年上半年研究生开题报告评议审核结果公示[答辩]2016下半年研究生论文答辩及学位评定 ...
- SQL Server与Oracle中的隔离级别
在SQL92标准中,事务隔离级别分为四种,分别为:Read Uncommitted.Read Committed.Read Repeatable.Serializable 其中Read Uncommi ...
- 需求分析Point
1.码段的查询结果的汇总值计算有问题.被删除的是否还算是被使用范围内呢?现在是即使废弃了也算使用的.这就有范围和重叠的问题,需要识别这种集合关系的数据好概念,并搞清楚他们的关系和概念.
- spm使用之七不用seajs改用headjs起步
这几天在看phpwind官方网站, 他们的前端用了一个叫做head.js的js加载器, 官方网站在 http://headjs.com/ 号称是你只需要在你的html文件中的<head>& ...