题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r (l ≤ r…
题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数位DP:http://blog.csdn.net/libin56842/article/details/11580497 */ #include <cstdio> #include <iostream> #include <algorithm> #include <c…
题目 https://nanti.jisuanke.com/t/17118 题意 有n个点0,1,2...n-1,对于一个点对(i,j)满足i<j,那么连一条边,边权为i xor j,求0到n-1的最大流,结果取模,n<=1e18 分析 可以写个最大流对数据找规律,但没找出来…… 然后只能取分析了,首先最大流等价于最小割 明确一定,0->n-1这个要先割掉 然后我们贪心,希望有一些点割掉与0相连的边,一些点割掉与n-1相连的边 我们去观察每个点与0相连和与n-1相连的两条边权值,容易发现…
老年选手需要多写一些思维题qwq. 通过打表很容易发现对于(i,j),值为(i-1)^(j-1)+1,然后本题就没了qwq. 矩阵差分还是很容易想到的,容斥成四个矩阵. 然后看到异或很容易想到三件事:数位DP.字典树.线性基.很容易发现后两种与本题不符,就是数位DP了,从高位到低位DP,f[i][0/1][0/1][0/1]表示到第i位,当前的x.y.x^y是否达到上界,然后直接暴力枚举当前位即可.因为q<=1e4怕memset多了出事,我用了滚动数组qwq. #include<bits/st…
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点的方案数. 思路: 打表找规律得到的序列是0,3,6,21,60,183,546,1641,4920,14763,通过肉眼看或者oeis可以得到规律为. dp计数:dp[i][j]表示在第i步时站在位置j的方案数,j的取值为[0,3],分别表示D,A,B,C点,转移方程肯定是从其他三个点转移. 代码…
Codeforces 题目传送门 & 洛谷题目传送门 蠢蠢的我竟然第一眼想套通项公式?然鹅显然 \(5\) 在 \(\bmod 10^{13}\) 意义下并没有二次剩余--我真是活回去了... 考虑打表找规律(u1s1 这是一个非常有用的技巧,因为这个 \(10^{13}\) 给的就很灵性,用到类似的技巧的题目还有这个,通过对这些模数的循环节打表找出它们的共同性质,所以以后看到什么特殊的数据或者数据范围特别大但读入量 \(\mathcal O(1)\) 的题(比如 CF838D)可以考虑小数据打…
题目传送门 似乎我的解法和官方题解不太一样 纪念自己独立做出来的一道难度 2800 的题. 我们记 \(ans(x)\) 为 \([444...44,x]\) 的答案,显然答案为 \(ans(r)-ans(l)\) 其次我们考虑 \(a_i\) 与 \(a_{i+1}\) 之间有什么联系. 不难发现从 \(a_i\) 变到 \(a_{i+1}\),也就是把 \(a_i\) 末尾一系列 \(7\) 改为 \(4\),再把从右往左数第一个 \(4\) 改为 \(7\). 这样我们就可以枚举末尾 \(…
Codeforces 题目传送门 & 洛谷题目传送门 一道数论与数位 dp 结合的神题 %%% 首先在做这道题之前你需要知道一个定理:对于质数 \(p\) 及 \(n,k\),最大的满足 \(p^{\alpha}\mid\dbinom{n}{k}\) 的 \(\alpha\) 为 \(k\) 与 \(n-k\) 在 \(p\) 进制下相加的进位次数.证明就考虑扩展 Lucas 定理,记 \(f(x)\) 为最大的满足 \(p^{\alpha}\mid x\) 的 \(\alpha\),那么由 \…
http://codeforces.com/problemset/problem/204/A 题意:给定一个[L,R]区间,求这个区间里面首位和末尾相同的数字有多少个 思路:考虑这个问题满足区间加减,我们只考虑[1,n],考虑位数小于n的位数的时候,我们枚举头尾的数是多少,然后乘上10的某幂次,再考虑位数相等时,从高位往低位走,先考虑头尾数字小于最高位的情况,也像刚才那个随便取,当头尾数字等于最高位时,从高往低走,先算不与这位相等的,走下一步就代表与这位相等.最后要记得判断一下如果原数字头等于尾…
大致题意: 有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了 那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个人的坐标. 题解: 两个人要相撞,当且仅当Xi-Ti=Xj-Tj,所以可以将Xi-Ti分组,对于同一组里的人会互相碰撞,不同组的不会,这样就只要考虑同一组里 的人,画个图可以发现,规律 然后根据规律化坐标即可 #include<cstdio> #include<cstring> #in…
B. Maximum of Maximums of Minimums time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the a…
<题目链接> 题目大意: 现在有无限个 1,5,10,50这四个数字,从中恰好挑选n个数字,问你这些数字的和总共有多少种不同的情况. 解题分析: 由于此题 n 的范围特别大,达到了1e9,所以猜想可能会有什么规律,使得答案在极短的时间内求解出来,于是就对本题前100项进行暴力打表,发现从第11项之后,每一项都与前一项相差49,然后本题就可以A了. /*#include <cstdio> //暴力打表找出前100项的规律 #include <map> #include &…
C. No to Palindromes! time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of th…
题意: 现在给你一个n,表示有2*n-1个方格,第奇数方格上会有一个数字 1-n按顺序放.第偶数个方格上是没有数字的.变动规则是排在最后一个位置的数字,移动到它前边最近的空位 . 直到数字之间没有空位.之后有q次询问.每次问你这个位置上的数是多少 题解: 1:  1 2:  1 2 3:  1 3 2 4:  1 3 2 4 5:  1 5 2 4 3 6:  1 4 2 6 3 5 7:  1 6 2 5 3 7 4 8:  1 5 2 7 3 6 4 8 9:  1 9 2 6 3 8 4…
E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you shoul…
Description Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question: Given two binary numbers aa and bb of length nn. How many different ways of swapping two digits in aa (only in aa, not bb) so tha…
A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the…
题意: 在经典Nim博弈的基础上增加了新的限制:如果从这堆石子中移走\(x\)个石子,那么之后就不能再从这堆移走\(x\)个. 分析: 因为之前的操作会对后面的转移有影响,所以在保存状态时还要记录哪些数量的石子可以移走. \(d(i,S)\)表示现在有\(i\)个石子,\(S\)中\(1\)的位置表示可以移走对应数量的石子,打表求出\(SG\)函数值. 打表代码: #include <cstdio> #include <cstring> bool vis[100]; int mex…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1536 首先,要知道值为n的答案,则可以这么去想,知道值为n - 1的答案,然后判断下,前面的数字能不能唯一确定n 然后,如果一个数是单独一个质数的k次方,这样是不能唯一确定的. 因为,比如要确定343 = 7 * 7 * 7 根据前面的数字,能被7整除,又能被49整除,不是能唯一确定吗?但是49本身也符合. #include <cstdio> #include <…
Description Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression: (1n + 2n + 3n + 4n) mod 5 for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e…
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define rep(i, a, b) for(int i=(a); i<(b); i++) #define sz(x) (int)x.size() #define de(x) cout<< #x<<" = &q…
传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher…
剑指 Offer 44. 数字序列中某一位的数字 Offer_44 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author WaleGarrett * @Date 2021/2/8 10:01 */ /** * 题目描述: * 数字以0123456789101112131415-的格式序列化到一个字符序列中.在这个序列中,第5位(从下标0开始计数)是5,第13位是1,第19位是4,等等. * 请写一个函数,求任意第n位对应的数字…
Codeforces 题面传送门 & 洛谷题面传送门 数位 dp 好题. 首先,由于是凸包,一但向量集合确定,凸包的形态肯定就已经确定了.考虑什么样的向量集合能够组成符合条件的凸包,我们假设第 \(i\) 个向量选了 \(c_i\) 次.因为凸包是首尾相连的,所以必然有 \(\sum\limits_{i=1}^nc_ix_i=0,\sum\limits_{i=1}^nc_iy_i=0\).上式也可写作 \(\sum\limits_{x_i>0}c_ix_i=\sum\limits_{x_i&…
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The b…
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description you the conditions of this task. There are 3 pivots: A, B, C. Initially, n disks of different diameter are placed on the pivot A: the smallest dis…
题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per test2 secondsmemory limit per test256 megabytes 问题描述 There have recently been elections in the zoo. Overall there were 7 main political parties: one…
链接:https://www.nowcoder.com/acm/contest/206/B来源:牛客网 题目描述 恬恬有一个nx n的数组.她在用这个数组玩游戏: 开始时,数组中每一个元素都是0. 恬恬会做某些操作.在一次操作中,她可以将某一行的所有元素同时加上一个值,也可以将某一列的所有元素同时加上一个值. 在几次操作后,一个元素被隐藏了.你能帮助她回忆隐藏的数是几吗? 输入描述: 第一行一个整数n(1≤ n≤ 1000).接下来n行每行n个整数表示数组a.第(i+1)行的第j个元素表示a i…
CodeForces - 204C Little Elephant and Furik and Rubik 个人感觉是很好的一道题 这道题乍一看我们无从下手,那我们就先想想怎么打暴力 暴力还不简单?枚举所有字串,再枚举所有位置,算出所有答案不就行了 我们自然不能无脑暴力,但是暴力可以给我们启发 我们知道所有对答案做出贡献的字符一定是相同的(废话) 所以我们可以O(n^2)首先枚举两个字符串中相同的字符然后再考虑如何贡献 然后计算出所有的方案下的值,再除以n*(n+1)*(2*n+1)/6 [不知…
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN]; int main(void) //Codeforce…