Homework of English

本文介绍了一个基于序列的数学问题背景下的英语作业难题,探讨了如何通过算法高效地解决该问题。主要内容包括输入输出格式说明、样例解释及核心算法实现。
Homework of English

The English teacher give Nobita a very very strange homework.
And Nobita am really doesn't konw why teacher gives him such a homwork.
Perhaps that's because of Nobita's English is very bad.
The homework is like this.
There are a integer sequence a[1],a[2],...,a[N] of length N, and two integer P and M.
And then there are Q queries.
Each query contains two integers L and R.
Nobita need to konw the value (a[L]*(P^0)+a[L+1]*(P^1)+a[L+2]*(P^2)+...+a[R]*(P^(R-L)))%M for each query.

And for any two queries L1,R1 and L2,R2,
if L1<L2 then R1<L2 or R1>=R2.

Input

There are lots of test case.
For each test case.
The first line contains integers N,P,M.
The second line contains integers a[0],b,c,d
And the sequence a will be got through this four numbers, that is a[i]=(a[i-1]*b+c)%d for 1<=i<=N.
The Third line contains a integer Q.
The next Q lines each line contain two integers L and R.

(1<=N<=5000000, 2<=P,M<=10^9, 1<=Q<=10^5, 1<=L<=R<=N, 1<=a[0],b,c,d<=10^9)

Output

For each query output one line.
Contain a integer indicates the answer.

Sample Input

5 3 10
3 4 5 6
2
2 4
3 3

Sample Output

5
3

f[i]=ix=1a[x]px1
ans=f[R]f[L1]pL
然后给定的M不一定与P互素, PL关于M的乘法逆元不一定存在

前缀和不行,那就考虑一下后缀和……

f[i]=a[i]+a[i+1]p+a[i+2]p2+...+a[n]pi
ans=f[L]f[R+1]prl+1

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<string.h>
#include<math.h>
#include<list>

using namespace std;

#define ll long long
#define pii pair<int,int>
const int inf = 1e9 + 7;

const int N = 5e6+5;
ll MOD;

ll f[N];

ll qPow(ll a,ll n){
    ll ans=1;
    ll t=a%MOD;
    while(n){
        if(n&1){
            ans=(ans*t)%MOD;
        }
        n>>=1;
        t=(t*t)%MOD;
    }
    return ans;
}

int main()
{
    //freopen("/home/lu/Documents/r.txt","r",stdin);
    ll n,p;
    while(~scanf("%lld%lld%lld",&n,&p,&MOD)){
        ll a0,b,c,d;
        scanf("%lld%lld%lld%lld",&a0,&b,&c,&d);
        f[0]=a0;
        for(int i=1;i<=n;++i){
            f[i]=(f[i-1]*b+c)%d;
        }
        f[n+1]=0;
        for(int i=n-1;i>=0;--i){
            f[i]=(f[i+1]*p+f[i])%MOD;
        }
        int q;
        scanf("%d",&q);
        while(q--){
            int l,r;
            scanf("%d%d",&l,&r);
            ll ans=((f[l]-f[r+1]*qPow(p,r-l+1))%MOD+MOD)%MOD;
            printf("%lld\n",ans);
        }
    }
    return 0;
}
内容概要:本文档围绕六自由度机械臂的ANN人工神经网络设计展开,涵盖正向与逆向运动学求解、正向动力学控制,并采用拉格朗日-欧拉法推导逆向动力学方程,所有内容均通过Matlab代码实现。同时结合RRT路径规划与B样条优化技术,提升机械臂运动轨迹的合理性与平滑性。文中还涉及多种先进算法与仿真技术的应用,如状态估计中的UKF、AUKF、EKF等滤波方法,以及PINN、INN、CNN-LSTM等神经网络模型在工程问题中的建模与求解,展示了Matlab在机器人控制、智能算法与系统仿真中的强大能力。; 适合人群:具备一定Ma六自由度机械臂ANN人工神经网络设计:正向逆向运动学求解、正向动力学控制、拉格朗日-欧拉法推导逆向动力学方程(Matlab代码实现)tlab编程基础,从事机器人控制、自动化、智能制造、人工智能等相关领域的科研人员及研究生;熟悉运动学、动力学建模或对神经网络在控制系统中应用感兴趣的工程技术人员。; 使用场景及目标:①实现六自由度机械臂的精确运动学与动力学建模;②利用人工神经网络解决传统解析方法难以处理的非线性控制问题;③结合路径规划与轨迹优化提升机械臂作业效率;④掌握基于Matlab的状态估计、数据融合与智能算法仿真方法; 阅读建议:建议结合提供的Matlab代码进行实践操作,重点理解运动学建模与神经网络控制的设计流程,关注算法实现细节与仿真结果分析,同时参考文中提及的多种优化与估计方法拓展研究思路。
Homework 4: Binocular Stereo November 6, 2025 Due Date: November 27, by 23:59 Introduction In this project, you will implement a stereo matching algorithm for rectified stereo pairs. For simplicity, you will work under the assumption that the image planes of the two cameras are parallel to each other and to the baseline. The project requires implementing algorithms to compute disparity maps from stereo image pairs and visualizing depth maps. To see examples of disparity maps, run python main.py --tasks 0 to visualize the com￾parison of disparity map generated by cv2.StereoBM and the ground truth. 1 Basic Stereo Matching Algorithm (60 pts.) 1.1 Disparity Map Computation (30 pts.) Implement the function task1 compute disparity map simple() to return the disparity map of a given stereo pair. The function takes the reference image and the second image as inputs, along with the following hyperparameters: • window size: the size of the window used for matching. • disparity range: the minimum and maximum disparity value to search. • matching function: the function used for computing the matching cost. The function should implement a simple window-based stereo matching algorithm, as out￾lined in the Basic Stereo Matching Algorithm section in lecture slides 08: For each pixel in the first (reference) image, examine the corresponding scanline (in our case, the same row) in the second image to search for a best-matching window. The output should be a disparity map with respect to the first (reference) image. Note that you should also manage to record the running time of your code, which should be included in the report. 1.2 Hyperparameter Settings and Report (30 pts.) Set hyperparameters in function task1 simple disparity() to get the best performance. You can try different window sizes, disparity ranges, and matching functions. The comparison of your generated disparity maps and the ground truth maps can be visualized (or saved) by calling function visualize disparity map(). 1 Computer Vision (2025 fall) Homework 4 After finishing the implementation, you can run python main.py --tasks 1 to generate disparity maps with different settings and save them in the output folder. According to the comparison of your disparity maps and ground truth maps under different settings, report and discuss • How does the running time depend on window size, disparity range, and matching function? • Which window size works the best for different matching functions? • What is the maximum disparity range that makes sense for the given stereo pair? • Which matching function may work better for the given stereo pair? With the results above • Discuss the trade-offs between different hyperparameters on quality and time. • Choose the best hyperparameters and show the corresponding disparity map. • Compare the best disparity map with the ground truth map, discuss the differences and limitations of basic stereo matching. 2 Depth from Disparity (25 pts.) 2.1 Pointcloud Visualization (20 pts.) Implement task2 compute depth map() to convert a disparity map to a depth map, and task2 visualize pointcloud() to save the depth map as pointcloud in ply format for visual￾ization (recommended using MeshLab). For depth map computation, follow the Depth from Disparity part in slides 08. You should try to estimate proper depth scaling constants baseline and focal length to get a better performance. The depth of a pixel p can be formulated as: depth(p) = focal length × baseline disparity(p) (1) For pointcloud conversion, the x and y coordinates of a point should match pixel coordinates in the reference image, and the z coordinate shoule be set to the depth value. You should also set the color of the points to the color of the corresponding pixels the reference image. For better performance, you may need to exclude some outliers in the pointcloud. After finishing the implementation, you can run python main.py --tasks 02 to generate a ply file using the disparity map generated with cv2.StereoBM, saved in the output folder. By modifying the settings of the hyperparameters in task1 simple disparity() and run￾ning python main.py --tasks 12, you can generate pointclouds with your implemented stereo matching algorithm under different settings and they will be saved in the output folder. 2 Computer Vision (2025 fall) Homework 4 2.2 Report (5 pts.) Include in your report and compare the results of the pointclouds generated with • disparity map computed using cv2.StereoBM • disparity map computed using your implemented algorithm under optimal settings you found in task 1. 3 Stereo Matching with Dynamic Programming (15 pts.) 3.1 Algorithm Implementation (10 pts.) Incorporate non-local constraints into your algorithm to improve the quality of the disparity map. Specifically, you are to implement the function task3 compute disparity map dp() with dynamic programming algorithms. You may refer to the Stereo Matching with Dynamic Programming section in lecture slides 08. Note that you should also manage to record the running time of your code, which should be included in the report. After finishing the implementation, you can run python main.py --tasks 3 to generate the disparity map and save it in the output folder. You can also run python main.py --tasks 23 to simultaneously generate pointclouds. 3.2 Report (5 pts.) Report the running time, the disparity map, and the pointcloud generated with dynamic programming algorithm. Compare the results with basic stereo matching algorithm. Submission Requirements • Due date of this homework is November 27, by 23:59. Late submission is acceptable but with a penalty of 10% per day. • Zip your code, report, and all the visualization results (including disparity maps and the pointclouds) into a single file named StuID YourName HW4.zip. A wrong naming format may lead to a penalty of 10%. Make sure that the zip file can be unzipped under Windows. • For the code, it should run without errors and can reproduce the results in your report. If you use artificial intelligence tools to help generate codes, explain in your report of (1) how you use them, and (2) the details of implementation in your own words. If your code simultaneously (1) is suspected to be generated by AI tools, and (2) cannot run properly, you may get a penalty of 100%. • For the report, either Chinese or English is acceptable. Please submit a single PDF file, which can be exported from LATEX, Word, MarkDown, or any other text editor. You may get a penalty of 10% if the file format is not correct. 3 Computer Vision (2025 fall) Homework 4 Hints Here are some supplemental materials: • cv2.StereoBM: https://docs.opencv.org/4.x/d9/dba/classcv_1_1StereoBM.html • cv2.StereoBeliefPropagation: https://docs.opencv.org/4.x/de/d7a/classcv_1_1cuda _1_1StereoBeliefPropagation.html
11-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值