uva---(11549)CALCULATOR CONUNDRUM
Problem C
CALCULATOR CONUNDRUM
Alice got a hold of an old calculator that can display n digits. She was bored enough to come up with the following time waster.
She enters a number k then repeatedly squares it until the result overflows. When the result overflows, only the n most
significant digits are displayed on the screen and an error flag
appears. Alice can clear the error and continue squaring the displayed
number. She got bored by this soon enough, but wondered:
“Given n and k, what is the largest number I can get by wasting time in this manner?”
Program Input
The first line of the input contains an integer t (1 ≤ t ≤ 200), the number of test cases. Each test case contains two integers n (1 ≤ n ≤ 9) and k (0 ≤ k < 10n) where n is the number of digits this calculator can display k is the starting number.
Program Output
For each test case, print the maximum number that Alice can get by repeatedly squaring the starting number as described.
Sample Input & Output
INPUT
2
1 6
2 99
OUTPUT
9
99
模拟题:
题意就是一个数,然后一直平方,然后求在这个过程中最大的前n位:
代码:
#include<cstring>
#include<set>
#include<iostream>
using namespace std;
long long mod[]={,,,,,,,,,};
int main(){
int n,test;
long long k;
cin>>test;
while(test--){
cin>>n>>k;
while(k/mod[n]>){ //截取高位
k/=;
}
long long res=k;
set<long long>sac;
while(sac.count(k)==){
sac.insert(k);
k*=k;
while(k/mod[n]>){ //截取高位
k/=;
}
if(k>res)res=k;
}
cout<<res<<endl;
}
return ;
}
uva---(11549)CALCULATOR CONUNDRUM的更多相关文章
- Floyd判圈算法 UVA 11549 - Calculator Conundrum
题意:给定一个数k,每次计算k的平方,然后截取最高的n位,然后不断重复这两个步骤,问这样可以得到的最大的数是多少? Floyd判圈算法:这个算法用在循环问题中,例如这个题目中,在不断重复中,一定有一个 ...
- 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 找规律加map
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11549 Calculator Conundrum (Floyd判圈算法)
题意:有个老式计算器,每次只能记住一个数字的前n位.现在输入一个整数k,然后反复平方,一直做下去,能得到的最大数是多少.例如,n=1,k=6,那么一次显示:6,3,9,1... 思路:这个题一定会出现 ...
- 【set&&sstream||floyed判环算法】【UVa 11549】Calculator Conundrum
CALCULATOR CONUNDRUM Alice got a hold of an old calculator that can display n digits. She was bored ...
- UVa 11549 计算器谜题(Floyd判圈算法)
https://vjudge.net/problem/UVA-11549 题意: 有一个老式计算器,只能显示n位数字,输入一个整数k,然后反复平方,如果溢出的话,计算器会显示结果的最高n位.如果一直这 ...
- UVa 11549 Open Credit System
题意:给出n个数,找出两个整数a[i],a[j](i < j),使得a[i] - a[j]尽量大 从小到大枚举j,在这个过程中维护a[i]的最大值 maxai晚于ans更新, 可以看这个例子 1 ...
- [UVa11549]Calculator Conundrum
题目大意:有一个只能显示n位数字的计算器,当溢出时只显示最高的n位. 输入k,要你不断平方,问你计算器显示的最大数是多少. 解题思路:这题的示数肯定会循环,那么我们关键就是找什么时候循环了. 可以用F ...
- 【图论】Floyd消圈算法
毫无卵用的百度百科 Definition&Solution 对于一个给定的链表,如何判定它是否存在环以及环的长度问题,可以使用Floyd消圈算法求出. 从某种意义上来讲,带环的链表在本质上是一 ...
随机推荐
- C#无需IIS构建XmlRpc服务器
准备 我们使用CookComputing.XmlRpcServerV2 3.0.0来构建XmlRpc服务器. 新建一个控制台项目,在项目中添加对CookComputing.XmlRpcServerV2 ...
- CSS3选择器 :nth-child(n) 详解
CSS3 :nth-child(n): http://demo.doyoe.com/css3/nth-child(n)/ 浏览器参照基准:IE9, Firefox, Chrome, Safari, O ...
- MySQL(五) —— 子查询
子查询(SubQuery)是指出现在其他SQL语句内的SELECT语句. 如: SELECT * FROM t1 WHERE col1 = (SELECT col2 FROM t2); 其中 SELE ...
- VS2008中开发智能设备程序的一些总结
原文链接:http://blog.csdn.net/citybug_nj/article/details/2598705 程序中包括四个部分: 系统配置 这个部分用来配置系统中的相关参数,参数包括数据 ...
- CUBRID学习笔记 19 sql语句1
创建 欢迎转载 ,转载时请保留作者信息.本文版权归本人所有,如有任何问题,请与我联系wang2650@sohu.com . 过错 create table tableName (字段名 字段类型 pr ...
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- 线程入门之实现Runnable接口和继承Thread类
线程的2种使用方式:实现Runnable接口和继承Thread类 1.实现Runnable接口 实现Runnable接口,必须实现run方法,也是Runnable接口中的唯一一个方法 class Ru ...
- Linux基础※※※※如何使用Git in Linux(一)
参考资料: 1. https://www.linux.com/learn/tutorials/796387-beginning-git-and-github-for-linux-users/ 2. h ...
- iOS - OC NSCache 缓存
前言 NSCache 是苹果提供的一个专门用来做缓存的类,当内存 "不足" 或超过限制的时候,会自动清理缓存,使用时可以指定缓存的数量和成本.用法与 NSMutableDictio ...
- iOS - Swift NSSize 尺寸
前言 结构体,这个结构体用来表示事物的宽度和高度. public typealias NSSize = CGSize public struct CGSize { public var width: ...