ny269 VF

 

VF

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述
Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most interesting facts such as Pythagor’s theorem are already proved? Correct! He is to think out something his own, original. So he thought out the Theory of Vasya’s Functions. Vasya’s Functions (VF) are rather simple: the value of the Nth VF in the point S is an amount of integers from 1 to N that have the sum of digits S. You seem to be great programmers, so Vasya gave you a task to find the milliard VF value (i.e. the VF with N = 109) because Vasya himself won’t cope with the task. Can you solve the problem?
 
输入
There are multiple test cases.
Integer S (1 ≤ S ≤ 81).
输出
The milliard VF value in the point S.
样例输入
1
样例输出
10


题意讲解:本题目是让你求10亿个数的每个位数的数字之和为s的,共有都少个;
例如:和为1的有1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000共有十个;
题意大概就是如此,输入一个S,然后求出和为s,的共有多少个;
可以用动态规划来做:
状态转移方程:

初始条件:dp[0][j]=1   j=1、2…9

状态转移方程:

dp[i][j]表示:和为i,不超过j个数相加的符合条件的数有多少个

dp[i][j]=sum{dp[i-k][j-1]  k=0、1…9}

代码如下:
       

 1 #include<iostream>
 2 using namespace std;
 3 int a[83][13];
 4 void fun()
 5 {
 6     int sum,n,i,j,k;
 7     for(i=0;i<=11;i++)
 8         a[0][i]=1;
 9     for(i=1;i<=81;i++)
10         for(j=1;j<=9;j++)
11         for(k=0;k<10 && i-k>=0;k++)
12            if(a[i-k][j-1])
13                a[i][j]+=a[i-k][j-1];
14 }
15 int main()
16 {
17     int t;
18     fun();
19     while(cin>>t)
20     {
21         if(t==1)
22             cout<<10<<endl;
23         else
24         cout<<a[t][9]<<endl;
25     }
26     return 0;
27 }

 


转载于:https://www.cnblogs.com/lovychen/p/3361963.html

Fortran程序: parameter(pi=3.1415926535) real kn real,allocatable :: vs(:,:),vf(:,:) a=1234.; n0=7; ny=100; u0=1. b=a/float(n0); ds=b/float(ny); nx=n0*ny errs=1.e-6; errf=1.e-6 allocate(vs(0:nx,0:ny),vf(0:nx,0:ny)) vs=0.; vs(1:nx-1,ny)=u0; vf=vs !---------------------------------------------------------- open(1,file='nvs.dat') do i=1,nx-1; x=float(i)*ds do j=1,ny-1; y=float(j)*ds err=1.; nc=0 do while(err.gt.errs) fnc=2.*float(nc)+1.; kn=pi*fnc/a t=sin(kn*x)*(1.-exp(-2.*kn*y))/(fnc*(exp(kn*(b-y))-exp(-kn*(b+y)))) err=abs(t) vs(i,j)=vs(i,j)+t nc=nc+1 enddo write(1,*) x,y,nc vs(i,j)=vs(i,j)*(4.*u0/pi) enddo enddo close(1) open(1,file='vs.dat') do i=0,nx; x=float(i)*ds do j=0,ny; y=float(j)*ds write(1,*) x,y,vs(i,j) enddo enddo close(1) !---------------------------------------------------------- err=1. do while(err.gt.errf) do i=1,nx-1; x=float(i)*ds do j=1,ny-1; y=float(j)*ds t=0.25*(vf(i+1,j)+vf(i-1,j)+vf(i,j+1)+vf(i,j-1)) if(i.ne.1.or.j.ne.1) then err0=abs(t-vf(i,j)); err=amax1(err,err0) else err=abs(t-vf(i,j)) endif vf(i,j)=t enddo enddo enddo open(1,file='vf.dat') do i=0,nx; x=float(i)*ds do j=0,ny; y=float(j)*ds write(1,*) x,y,vf(i,j) enddo enddo close(1) !--------------------------- a0=0.5*a; b0=0.8*b open(1,file='a0.dat'); open(2,file='b0.dat') i=nint(a0/ds); do j=0,ny; write(1,*) float(j)*ds,vs(i,j),vf(i,j); enddo; close(1) j=nint(b0/ds); do i=0,nx; write(2,*) float(i)*ds,vs(i,j),vf(i,j); enddo; close(2) !--------------------------- write(*,*) err,i0,j0 deallocate(vs,vf) stop end
06-07
clc clear x1=4;%x方向长4 y1=4;%y方向长4 NN=100;%等分成100份 dx=x1/NN;dy=y1/NN; x=0:dx:4; y=0:dy:4; [Nx,Ny]=meshgrid(x,y);%x,y方向画网格 %meshgrid 解释,这是matlab中画网格的一条命令,[nx,ny]meshgrid(x,y); %x,y 是向量,比如: %%clc;clear;close all; %%[X,Y]=meshgrid(-2:0.1:2,-2:0.1:2); %%Z=exp(-X.^2-Y.^2); %%mesh(X,Y,Z);%线框图 %%figure(); %%surf(X,Y,Z);%表面图 %%shading interp;可以通过取(x,y)处的值来获取z的坐标,进而绘制z的函数图像 Nz=ones(length(x),length(x));%z方向高度1 R=5;%刀具半径mm b=pi/6;%刀具螺旋 n_feed=9;%进给次数 time=2;%进给总时间 dw=0.02;%离散切削点间隔 alpha=pi/8;%侧偏角 beta=pi/8;%前倾角 ap=2.5;%切削深度 L=sqrt(R^2-(R-ap)^2);%理论切削长度 delta=asin(L/R);%理论有效切削角度 cs=0;%切削位置最小角度 pointnumber=ceil(R*delta/dw)+1; tp=1;%离散的第一个切削点 phase=[0 0 pi/2 pi/2 0 0 pi/2 pi/2 0];%初始相位角可根据需要自行设置 x0=0; y0=0; z0=R+max(max(Nz))-ap;%球头铣刀初始中心位置 vf=4;%进给速度 w=5*pi;%转速 fp=0.7;%行距 e=0.5; epsilon=0.01; while (tp<=pointnumber) J=cs+((tp-1)*dw)/R;%第一个离散点角度值 for ii=1:n_feed phase1=phase(1,ii); for k=1:2%两个刀齿 jj=phase1+2*pi*(k-1)/2;%第K齿初始相位角 for t=0:0.0005:time M=[R*sin(J)*cos(tan(b)*log(cot(J/2)));R*sin(J)*sin(tan(b)*log(cot(J/2)));-R*cos(J);1];%计算离散点在刀具坐标系中坐标 M1=[1 0 0 e*cos(epsilon);0 1 0 e*sin(epsilon);0 0 1 0;0 0 0 1];%轴向窜动的影响 M2=[cos(jj+w*t) -sin(jj+w*t) 0 0;sin(jj+w*t) cos(jj+w*t) 0 0;0 0 1 0;0 0 0 1];%刀齿坐标系相对于刀具坐标系转换矩阵 M3=[1 0 0 0;0 cos(alpha) -sin(alpha) 0;0 sin(alpha) cos(alpha) 0;0 0 0 1];%刀具侧偏角 M4=[cos(beta) -sin(beta) 0 0;sin(beta) cos(beta) 0 0;0 0 1 0;0 0 0 1];%刀具前倾角 M5=[1 0 0 x0+(ii-1)*fp;0 1 0 y0+vf*t;0 0 1 z0;0 0 0 1];%单向走刀时,主轴坐标系相对于工件坐标系转换矩阵 z=M5*M4*M3*M2*M1*M;%刀齿上任意一点在坐标系内坐标 X=z(1,:); Y=z(2,:); Z=z(3,:);%分别提取矩阵Mwp,中X,Y,Z元素 if (0<=X&&X<=4)&&(0<=Y&&Y<=4)%判提取点是否在工件网格范围内 iii=round(X/0.04+1);jjj=round(Y/0.04+1);%获取该网格点Z值大小 Zj=Nz(iii,jjj); if Z<Zj%判断Zwp网格点Z值大小 Nz(iii,jjj)=Z; %用Zwp代换该网格点Z值 end end end end end tp=tp+1; end zz=min(min(Nz)); zzz=(Nz-zz); Nzz=zzz(2:100,2:100); Nxx=Nx(2:100,2:100); Nyy=Ny(2:100,2:100); [Ray,midliney]=Racountingy(dy,NN,NN+1,zzz);%垂直于加工方向 [Rax,midlinex]=Racountingx(NN+1,NN+1,zzz,Nx(1,:)); surf(Nxx,Nyy,Nzz) shading interp; 解析代码
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值