//never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值int times[20];//mn次数int timess[20];//mx次数int len;int mn;int mx;int kk,sum;void solve(){    kk=0,sum=0;    if(a[times[1]]==0)        return;    for(int i=1;i…
#include<bits/stdc++.h>using namespace std;int a[100010];char s[20];int zhiren[100010];vector<int>haoren[100010];int sum=0;void dfs(int x,int y,int flag){    if(x==y)        flag=1;//如果和被指认的人相同,则定为狼    sum+=flag;//并且后面直接或间接认为刚才那个是狼的人是好人的人也都是狼 …
Glad You Came Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1489    Accepted Submission(s): 629 Problem Description Steve has an integer array a of length n (1-based). He assigned all the e…
#include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1<<10];int ans[1<<10];char c[10];int t;void add(int &x,int y){    x=x+y>=mod?x+y-mod:x+y;}void del(int &x,int y){    x=x-y<0?x-y+mo…
Rikka with Competition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 445    Accepted Submission(s): 366 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situ…
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1440    Accepted Submission(s): 721 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situatio…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6630 题意为求出1-n,n个数的全排列中有多少种方案满足第一位为x,第n位为y,且相邻数字绝对值之差不超过2. 我们可以预处理d数组,定义d[i]表示1-i个数的全排列中以1为第一位,i为第i位且相邻数字绝对值之差不超过2的方案数. 则第i位为i,可以由第i-1位转移,表示i位与i-1位数字绝对值之差为1,则$d[i]+=d[i-1]$,也可以由第i-3位转移,表示第i-1位为i-2,第i-2位为i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6624 题意为求最小的b满足$a*b^{-1}\equiv x(modp)$. 把式子化简一下: $a\equiv b*x(modp)$ $a=b*x-p*y$ $\because 0<a<b$ $\therefore 0<b*x-p*y<b$ $0<b*x-p*y\Rightarrow \frac{p}{x}<\frac{b}{y}$ $b*x-p*y<b\Right…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6629 题意求字符串的每个后缀与原串的最长公共前缀之和. 比赛时搞东搞西的,还搞了个后缀数组...队友一说扩展kmp我都自闭了,这不就是扩展kmp的第一步,求原串的每个后缀与原串的最长公共前缀嘛. 需要注意的就是题目准确问的是按照文中所给的代码执行需要判断几次,如果最长公共前缀等于该后缀的长度,则会判断Next[i]次(Next[i]为以i为开始的后缀与原串的最长公共前缀).如果不等,则会判断Next…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6628 题意为求字典序第k小的差异数组,差异数组p满足p[i]=a[i+1]-a[i]. 头铁的爆搜,因为差异数组的范围为[1-n,n-1],所以爆搜的时候可以先将原数组每位+n,记录数字出现的上下界,最后求答案的时候再减去下界即可. #include<iostream> #include<cstdio> #include<algorithm> using namespace…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6625 大意为给你两个数组a和b,对应位置异或得到c数组,现在可以将a,b数组从新排序求c数组,使得字典序最小. 大致的做法就是用两个数组中的数字二进制 建两颗字典树,同时记录每个位置的个数.然后在两颗字典树上同时dfs,优先往0-0和1-1方向走,不能走再走0-1,1-0方向. 因为0-0和1-1两种情况不分先后,所以走出来的不一定是最小的,走完得到的c数组要排序. #include<iostrea…
https://vjudge.net/contest/317493#problem/I…
题意:长度为n的序列,有一次翻转区间的机会,问最长不减序列 题解:如果没有翻转区间的机会,有两个做法. 一是dp[i]表示以i结尾的最长序列 dp[i]=max(dp[i],dp[j]+1)  (j<=i). 二是那个抽牌替换的解法. 这道题可以翻转但是值域很小,所以考虑最长子序列和值域的关系. 选择第一种解法改进. 显然不翻转的话是序列A与 序列B ={0123456789} 来匹配,B中的元素可以被匹配到多次. 现在要求翻转一次后的最长子序列,直接翻转A的复杂度是C(n,2)*n*10. 考…
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之前的状态. 回退的时候,如果暴力点,就直接将每步所操作的线段树都存下来,然后直接翻阅回去,这种方法虽然简单,但是对空间和时间的需求太大了,肯定不能过. 所以这时候我们就可以选择可持久化操作. 可持久化是数据结构里面的一种方法,其总体就是把一个数据结构的历史状态全部都保存下来,从而能够快速的查找之前出…
Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 184    Accepted Submission(s): 132 Problem Description Alice and Bob are playing a game.The game is played on a set of positive integers from…
躺了几天 终于记得来填坑了 1001 Ascending Rating   (hdoj 6319) 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6319 单调队列 具体有点类似双端队列滑动窗口 题意:在一个队列中 每次都给定一个固定长度的区间 从i=1开始向后移动 每次在这个区间中进行a[i]和a[j]的比较 若a[i]<a[j] count++ 最大值更新为a[j] ,每个区间的最大值和count都分别异或i 求出分别的和 求区间最大值可以比较容易…
#include<bits/stdc++.h>using namespace std;int n,m;int x,y;int num,cnt;int degree[100007],vis[100007],viss[400040],first[100007];vector<int>jidian,road[100007];struct node{    int v,next;}xu[400040];void init()//初始化{    num=0,cnt=1;    memset(…
Problem I. Count Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 42    Accepted Submission(s): 16 Problem Description Multiple query, for each n, you need to getn i-1∑ ∑ [gcd(i + j, i - j) = 1…
题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> #include <algorithm> #include <cstdio> #include<cstring> using namespace std; int t,n; ],str2[]; ]; int main(){ // freopen("cin.txt&q…
题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int main() { int T,n,a; scanf("%d",&T);…
题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } int main() { int t; ci…
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(long long a,long long b) { if(!b) return a; return gcd(b,a%b); } ]; int main() { int T,n; scanf("%d",&…
题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^20-1种情况来说处理出每一种情况的后继状态,求出sg值,进行异或即可. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> using namespace std;…
Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your job is simple, for each task, you should output Fn module 109+7.   Input The first line has only one integer T, indicates the number of tasks. Then,…
Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 474    Accepted Submission(s): 202 Problem Description Kazari has an array A length of L, she plans to generate an…
Problem Description Before the start of contest, there are n ICPC contestants waiting in a long queue. They are labeled by 1 to n from left to right. It can be easily found that the i-th contestant's QodeForces rating is ai.Little Q, the coach of Qua…
题目链接 Problem Description There are $$$n$$$ intersections in Bytetown, connected with $$$m$$$ one way streets. Little $$$Q$$$ likes sport walking very much, he plans to walk for q days. On the $$$i$$$-th day, Little $$$Q$$$ plans to start walking at t…
题目链接 Problem Description Chiaki is interested in an infinite sequence $$$a_1,a_2,a_3,...,$$$ which is defined as follows: $$$a_n= \begin{cases} 1, & \text{$$$n=1,2$$$} \\ a_{n-a_{n-1}}+a_{n-1-a_{n-2}} & \text{$$$n\ge 3$$$} \end{cases}$$$ Chiaki wo…
题目链接 Problem Description In a galaxy far, far away, there are two integer sequence a and b of length n. b is a static permutation of 1 to n. Initially a is filled with zeroes. There are two kind of operations: 1.add l r: add one for $$$a_l, a_{l+1}..…
题目链接 Problem Description Chiaki has an array of n positive integers. You are told some facts about the array: for every two elements $$$a_i$$$ and  $$$a_j$$$ in the subarray $$$a_{l,r} (l ≤ i < j ≤ r )$$$, $$$a_i≠a_j$$$ holds. Chiaki would like to fi…