标签归档:hdu

hdu 6061 RXD and functions(NTT)

Problem Description
RXD has a polynomial function f(x), f(x)=∑ni=0cixi
RXD has a transformation of function Tr(f,a), it returns another function g, which has a property that g(x)=f(x−a).
Given a1,a2,a3,…,am, RXD generates a polynomial function sequence gi, in which g0=f and gi=Tr(gi−1,ai)
RXD wants you to find gm, in the form of ∑mi=0bixi
You need to output bi module 998244353.
n≤105

Input
There are several test cases, please keep reading until EOF.
For each test case, the first line consists of 1 integer n, which means degF.
The next line consists of n+1 intergers ci,0≤ci<998244353, which means the coefficient of the polynomial. The next line contains an integer m, which means the length of a. The next line contains m integers, the i - th integer is ai. There are 11 test cases. 0<=ai<998244353 ∑m≤105 Output For each test case, output an polynomial with degree n, which means the answer. Sample Input 2 0 0 1 1 1 Sample Output 1 998244351 1 Hint $(x - 1) ^ 2 = x^2 - 2x + 1$

现在才学会NTT,现在才把这个水题补了,我是不是没救了啊?
进行一波推式子的工作:
\(g(0)=f(x),g(1)=f(x-a[1]),g(2)=f(x-a[1]-a[2]),…,g(m)=f(x-\sum_{i=1}^{m} a[i])\)。
所以实际上要求的是\(f(x-\sum_{i=1}^{m} a[i])\)。
展开得\(\sum_{i=0}^{n}c_i*(x-sum)^{i}\),通过二项式定理得到\(\sum_{i=0}^{n}c_i \sum_{j=0}^{i} \binom{i}{j} (-a)^{i-j}x^{j}\)。
因为我们要求的是\(x^{j}\)的系数,所以我们尽量让外层为j指标。交换求和次序后得到\(\sum_{j=0}^{n}\sum_{i=j}^{n} c_i \frac{i!}{(j-i)!j!} (-a)^{i-j}x^{j}\)。
得到了\(x^{j}\)的系数表达式,并且用i来替换i-j得到:\(\sum_{i=0}^{n-j}\frac{C_{i+j}*(i+j)!}{i!j!}*(-a)^{i}\)。
\(D[n-j]=\frac{1}{j!}*\sum_{i=0}^{n-j}A[i]B[n-i-j]\)。其中\(A[i]=\frac{(-a)^{i}}{i!},B[i]=c_i*(i!)\)。
然后就NTT好了。。。没有除j的阶乘调了半天,以及a的次幂没加负号,各种下标打错。。

hdu 6252 Subway Chasing(差分约束系统)

Problem Description
Mr. Panda and God Sheep are roommates and working in the same company. They always take subway to work together. There are N subway stations on their route, numbered from 1 to N. Station 1 is their home and station N is the company.
One day, Mr. Panda was getting up later. When he came to the station, God Sheep has departed X minutes ago. Mr. Panda was very hurried, so he started to chat with God Sheep to communicate their positions. The content is when Mr. Panda is between station A and B, God Sheep is just between station C and D.
B is equal to A+1 which means Mr. Panda is between station A and A+1 exclusive, or B is equal to A which means Mr. Panda is exactly on station A. Vice versa for C and D. What’s more, the communication can only be made no earlier than Mr. Panda departed and no later than God Sheep arrived.
After arriving at the company, Mr. Panda want to know how many minutes between each adjacent subway stations. Please note that the stop time at each station was ignored.

Input
The first line of the input gives the number of test cases, T. T test cases follow.
Each test case starts with a line consists of 3 integers N, M and X, indicating the number of stations, the number of chat contents and the minute interval between Mr. Panda and God Sheep. Then M lines follow, each consists of 4 integers A, B, C, D, indicating each chat content.
1≤T≤30
1≤N,M≤2000
1≤X≤109
1≤A,B,C,D≤N
A≤B≤A+1
C≤D≤C+1

Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the minutes between stations in format t1,t2,…,tN−1. ti represents the minutes between station i and i+1. If there are multiple solutions, output a solution that meets 0=tc
ta+x<=td 否则 tb+x>tc
ta+x

hdu 5929 Basic Data Structure

Problem Description
Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack:

 PUSH x: put x on the top of the stack, x must be 0 or 1.
 POP: throw the element which is on the top of the stack.

Since it is too simple for Mr. Frog, a famous mathematician who can prove “Five points coexist with a circle” easily, he comes up with some exciting operations:

REVERSE: Just reverse the stack, the bottom element becomes the top element of the stack, and the element just above the bottom element becomes the element just below the top elements… and so on.
QUERY: Print the value which is obtained with such way: Take the element from top to bottom, then do NAND operation one by one from left to right, i.e. If  atop,atop1,,a1 is corresponding to the element of the Stack from top to the bottom, value=atop nand atop1 nand … nand a1. Note that the Stack will notchange after QUERY operation. Specially, if the Stack is empty now,you need to print ”Invalid.”(without quotes).

By the way, NAND is a basic binary operation:

 0 nand 0 = 1
 0 nand 1 = 1
 1 nand 0 = 1
 1 nand 1 = 0

Because Mr. Frog needs to do some tiny contributions now, you should help him finish this data structure: print the answer to each QUERY, or tell him that is invalid.

 

Input
The first line contains only one integer T (T20), which indicates the number of test cases.

For each test case, the first line contains only one integers N (2N200000), indicating the number of operations.

In the following N lines, the i-th line contains one of these operations below:

 PUSH x (x must be 0 or 1)
 POP
 REVERSE
 QUERY

It is guaranteed that the current stack will not be empty while doing POP operation.

 

Output
For each test case, first output one line “Case #x:w, where x is the case number (starting from 1). Then several lines follow,  i-th line contains an integer indicating the answer to the i-th QUERY operation. Specially, if the i-th QUERY is invalid, just print “Invalid.“(without quotes). (Please see the sample for more details.)

 

Sample Input
2 8 PUSH 1 QUERY PUSH 0 REVERSE QUERY POP POP QUERY 3 PUSH 0 REVERSE QUERY

 

Sample Output
Case #1: 1 1 Invalid. Case #2: 0

Hint

In the first sample: during the first query, the stack contains only one element 1, so the answer is 1. then in the second query, the stack contains 0, l (from bottom to top), so the answer to the second is also 1. In the third query, there is no element in the stack, so you should output Invalid.

真搞不懂现在看起来这么简单的一个题,当时比赛的时候为什么能让我一个小时没写出来。。。
0 nand 任何数都是1,所以我们找到最靠近栈底的0(可能没有),然后数后面有几个1就可以了。
可以用双端队列模拟操作的过程。