题解 CF171A 【Mysterious numbers - 1】】的更多相关文章

题解-Roman and Numbers 前置知识: 数位 \(\texttt{dp}\) </> \(\color{#9933cc}{\texttt{Roman and Numbers}}\) 给定 \(n\) 和 \(m\),求将 \(n\) 的各位数字重新排列(不允许有前导 \(0\)),求可以构造几个能被 \(m\) 整除. 数据范围:\(1\le n\le 10^{18}\),\(1\le m\le 100\). 用数位 \(\texttt{dp}\) 代码又短时间又优又好理解,为什…
又是愚人节题目qwq-- 说一下题意吧: 把第1个数翻转后加第二个数 具体思路: 1.定义变量,进行输入 int a,b; cin>>a>>b; 2.定义一个变量c,作为存储第1个数的翻转 int c; 3.写出翻转第一个数的代码 while(b!=0) { c*=10; c+=b%10; b/=10; } c*10指把c扩大10倍,最后一位变成0 c+=b%10指将b目前的个位数赋值给c b/=10把b除以10最后一位则为原来的十位数 4.输出a+c即可 代码如下: #inclu…
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 ->…
题目: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -&…
题目: 两个数字求和,数字用链表表示,每一个结点代表一位.链表顺序与数字顺序相反,即表头存放数字的最低位. 解法: 分别遍历两个链表的每个结点,对两个结点求和即可.要维护一个变量保存每次相加之后的进位. 更常见的,链表顺序与数字顺序相同,那么做一次链表逆序,求和之后再逆序回来即可. 代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int…
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #include <cstdio> #include <algorithm> #include <map> #include <string> #include <string.h> using namespace std; ][]={"tret&…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789775.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 水题,就是统计n个数的数位和有多少个不同的,并且输出即可. #include <iostream> #include <cstdio> #include <algorithm> #include <string> #in…
这题没有压行就成 \(\texttt{Hard Version}\) 最短代码解了( 要知道这题那么 \(sb\) 就不啃 \(D\) 和 \(E\) 了. \(\texttt{Solution}\) 首先有一个非常简单但是错误的多重背包的想法: 让分拆出来的 \(k\) 个数中,每一个数在十进制下每一位都是 \(0, 3, 6\) 或 \(9\),于是对于第 \(x\) 位把 \(3k\) 个大小为 \(3 \times 10^x\), 价值为 \(F_x\) 的物品丢进多重背包里面,然后输出…
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful…
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 ->…
题目: Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 7], you should return 4. 解答: 假如说5:101  7:111  连续几个数相与的规律:一,仅仅要是同样的位置的数字不同样最后那个位置的结果一定是0 .二,…
[题目描述] You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in forward order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the…
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1, a^p == a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, known as…
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers. Write a program to find and pri…
题目: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two num…
懒得复制,戳我戳我 Solution: 我感觉我也说不太好,看Awson的题解吧. 说一点之前打错的地方: 连边存的是hash后的数组下标 if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==1){ if(f==0)printf("Alice\n");else printf("Bob\n"); continue; } if(ans[ num( C[a.hash()] , C[b.hash()] ) ]==-1){ if(f==0)…
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.gitbooks.io/leetbook/ ` 2.Add Two Numbers [M] Add Two Numbers M 题目 思路 代码 更精巧的代码 题目 You are given two linked lists representing two non-negative numbers. The…
Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assum…
Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6347   Accepted: 3740 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth…
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets…
更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description In mathematical terms, the sequence \(F_n\) of Fibonacci numbers is defined by the recurrence relation \[F_1 = 1; F_2 = 1; F_n = F_n - 1 + F_n - 2 (n > 2)\] DZY loves Fibonacci numbers ver…
Description Polycarp has guessed three positive integers \(a\), \(b\) and \(c\). He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order - their pairwise sums (three numbers) and sum of all three numbers (one n…
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets…
CodeChef-RNDRATIO Mysterious Ratio 题意简述: 对每个 \(1 \le i \le n\) ,随机选择一个数 \(A_i\) ,满足 \(L_i \le A_i \le R_i\) ,求 \(\mathrm{lcm}_{i=1}^n A_i\) 的期望. \(1 \le n \le 10^5\) , \(1 \le L_i \le R_i \le 10^5\) . Example Input: 2 1 1 3 2 2 4 5 5 Example Output:…
# 题意:高桥 くん 有一个边长为 N 的三枚镜子构成的正三角形 , 顶点为 a, b, c. 他有一个超级步枪 , 放在 AB 段的P点上,使得 AP=X . 并沿着平行于 BC 的方向发射一道光 . 光以直线传播 , 以镜子的形式反射 , 但是有一个特殊的地方 : 它会被自己的轨迹反射 , 当光回到步枪的时候 , 光被吸收 .  下面的图显示了当 n=5 ,x=2 时的光轨迹 . 求出光线的总长度 .# 题解:### 本体采用递归求解图中射出的第一条线加上第二条线就等于线段 ab : 所以递…
Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据范围:\(1\leqslant n,\sum n\leqslant 2\times 10^5\). Solution 看到本题的唯一一篇主席树+二分的题解里面并没有说最巧妙的方法是什么,那我就来给大家讲讲吧qwq. 对于每一个 \(m\),我们不妨弄个双指针 \(l,r\),然后从 \(1\) 的位…
[题目] D. Mysterious Crime [描述] 有m个n排列,求一共有多少个公共子段. 数据范围:1<=n<=100000,1<=m<=10 [思路] 对于第一个排列来说,如果第k个位置开始往后L长的子段是一个公共的子段,那么从k开始往后数1,2,...,L-1长的子段都是公共的子段:如果第k个位置开始往后L长的子段是一个公共的子段,但第k个位置开始往后L+1长的子段不是一个公共的子段,那么位置k到位置k+L中任一位置j开始往后直到位置k+L的子段都不是公共的子段.这就…
题目来源: https://leetcode.com/problems/sum-root-to-leaf-numbers/ 题意分析: 一棵树,从跟节点到叶子节点比如1->2那么这个叶子代表12,计算所有叶子的和. 题目思路: 这题主要是怎么计算叶子的数值.leaf = node.sum * 10 + leaf.val.记录所有叶子的数值,然后相加即可. 代码(python): # Definition for a binary tree node. # class TreeNode(objec…
题目来源: https://leetcode.com/problems/add-two-numbers/ 题意分析: 这道题目是要将两个单链条相加.输出得到的新链条. 题目思路: 不难发现,其实题目就是要我们模拟加法的实现.那么,我们就直接从低位(链条第一位)开始,同位相加,满10就往高位+1. 代码(python): # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): #…
原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因为\(7+1=8\) \(f(9)=1\),因为\(9+1=10→1\) \(f(10099)=101\),因为\(10099+1=10100→1010→101\) 我们可以多次进行函数\(f(x)\)的运算,从而让一个数\(x\)转换为另一个数,例如\(10098\)可以转换为\(102\),因为…