第八届省赛 B:Quadrat (打表找规律)
Description
It is well-known that for any n there are exactly four n-digit numbers (including ones with leading zeros) that are self-squares: the last ndigits of the square of such number are equal to the number itself. These four numbers are always suffixes of these four infinite sequences:
...0000000000
...0000000001
...8212890625
...1787109376
For example, 093762 =87909376, which ends with 09376.
You are required to count the numbers that are almost self-squares: such that each of the last n digits of their square is at most d away from the corresponding digit of the number itself. Note that we consider digits 0 and 9 to be adjacent, so for example digits that are at most 3 away from digit 8 are 5, 6, 7, 8, 9, 0 and 1.
Input
The first line contains the number of test cases t,1≤t≤72. Each of the next t lines contains one test case: two numbers n(1≤n≤ 18) and d(0≤ d≤3).
Output
For each test case, output the number of almost self-squares with length n and the (circular) distance in each digit from the square at most d in a line by itself.
Sample Input
2 5 0 2 1
Sample Output
4 12
Hint
In the second case, number 12's almost self-squares are: 00, 01, 10, 11, 15, 25, 35, 66, 76, 86, 90, 91
题意:
求满足以下条件
①.这个数为n位(可以有前导零)
②.取它的平方的后n位,与它本身每一位对应之差≤d(这里的差指的是数字之间的距离,而这个距离是将数字按圈排列,0与9相邻所求得的)
的数字的个数。
题解:
打表吧
规律就是 res[i][j] = res[i-1][j]*(2*j+1)
代码:
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define is_lower(c) (c >= 'a' && c <= 'z') #define is_upper(c) (c >= 'A' && c <= 'Z') #define is_alpha(c) (is_lower(c) || is_upper(c)) #define is_digit(c) (c >= '0' && c <= '9') #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define IO \ ios::sync_with_stdio(); \ cin.tie(); \ cout.tie(); #define For(i, a, b) for (int i = a; i <= b; i++) typedef long long ll; typedef unsigned long long ull; const ll inf = 0x3f3f3f3f; ; const ll inf_ll = (ll)1e18; const ll mod = 1000000007LL; ; ll res[][]; void init() { res[][] = res[][] = ; res[][] = res[][] = ; ; i < ; i++) { ;j <= ; j++) res[i][j] = res[i-][j] * ( * j + ); } } int main() { init(); int T; cin >> T; while(T--){ int n,d; cin>>n>>d; cout << res[n][d] << endl; } ; }
第八届省赛 B:Quadrat (打表找规律)的更多相关文章
- 【NOIP 模拟赛】中值滤波 打表找规律
对于这样看起来不像什么算法也没什么知识点的题,一脸懵逼的话不是手推规律就是打表找规律......... 当然还有一些超出你能力之外的数学题...... #include <cstdio> ...
- 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu_5894_hannnnah_j’s Biological Test(打表找规律)
题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...
- hdu_5795_A Simple Nim(打表找规律的博弈)
题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...
随机推荐
- 一道ioccc题目
国际C语言混乱大赛的一个题: main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"f ...
- [剑指Offer] 40.数组中只出现一次的数
题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. [思路]此题考察的是异或运算的特点:即两个相同的数异或结果为0. 此题用了两次异或运算特点: ( ...
- 安装与配置JDK
第一步:下载jdk-7-linux-i586.tar.gzwget -c http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586. ...
- P3509 [POI2010]ZAB-Frog
题目描述 On the bed of one particularly long and straight Byteotian brook there lie rocks jutting above ...
- P1368 工艺
题目描述 小敏和小燕是一对好朋友. 他们正在玩一种神奇的游戏,叫Minecraft. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工艺品最左边的方 ...
- 网络编程:listen函数
listen函数仅由TCP服务器调用,它做两件事: 当socket函数创建一个套接字时,它被假设为一个主动套接字,也就是说,它是一个将调用connect发起连接的客户套接字.listen函数把一个未连 ...
- HTML5 canvas流体力学效果
某人用Java搞了一个流体力学的演示:http://grantkot.com/MPM/Liquid.html. 下面是 HTML 5版的流体力学演示(推荐使用Chrome浏览器浏览): 效果演示 &l ...
- Spring AOP execution表达式
Spring中事务控制相关配置: <bean id="txManager" class="org.springframework.jdbc.datasource.D ...
- 洛谷P1522 牛的旅行 Cow Tours
---恢复内容开始--- P1522 牛的旅行 Cow Tours189通过502提交题目提供者该用户不存在标签 图论 USACO难度 提高+/省选-提交该题 讨论 题解 记录 最新讨论 输出格式题目 ...
- linux网络编程系列-TCP/IP模型
### OSI:open system interconnection ### 开放系统互联网模型是由ISO国际标准化组织定义的网络分层模型,共七层 1. 物理层:物理定义了所有电子及物理设备的规范, ...