第八届省赛 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时 ...
随机推荐
- js+jquery 常用选择器函数
一.获取当前标签 JS: this,如下: <button onclick="fun(this)"></button> Jquery,如下: $(" ...
- TCP的挥手协议和握手协议
三次握手协议:三次握手协议的主要过程是交互彼此之间的初始序列号,如果没有确认的ACK帧可以么?肯定是可以的 client A -------> server B client A 发送了自己的初 ...
- PHP的报错级别并返回当前级别error_reporting()
定义和用法:error_reporting() 设置 PHP 的报错级别并返回当前级别.函数语法:error_reporting(report_level) 如果参数 level 未指定,当前报错级别 ...
- [洛谷P3195][HNOI2008]玩具装箱TOY
题目大意:有n个物体,大小为$c_i$.把第i个到第j个放到一起,容器的长度为$x=j-i+\sum\limits_{k-i}^{j} c_k$,若长度为x,费用为$(x-L)^2$.费用最小. 题解 ...
- ng websocket
ng使用websocket 1.安装依赖库npm install ws --save 2.安装类型定义文件 npm install @types/ws --save 3.编写服务 import { I ...
- background-color和background-image问题
今天撸码的时候发现需要background-color和background-image 一起用,才开始考虑两个可不可以一起用 查阅多方资料才知道可以写成background:color url() ...
- 转:java 帐号激活与忘记密码 实例
原文链接:http://endual.iteye.com/blog/1613679 一.帐户激活 在 很多时候,在某些网站注册一个用户之后,网站会给这个用户注册时填写的email地址发送一封帐户激 ...
- 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...
- JS组件入门
用React感觉component老好用了. 那如何用原生JS来模拟实现React中的component方法呢:http://huziketang.com/blog/posts/detail?post ...
- 基于SSM框架web搜索功能的实现
这里适合选用于jsp搭建的网站,数据库采用MySQL 一.HTML <div class="header_search"> <input type="t ...