2018icpc南京现场赛-G Pyramid
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<cmath> #include<map> #include<vector> #define ll long long using namespace std; double a[20][20],b[20]; int n; int main() { n=5; b[1]=1.0; b[2]=5.0; b[3]=15.0; b[4]=35.0; b[5]=70.0; double c[20][20]={{0,0,0,0,0,0},{0,1,1,1,1,1},{0,16,8,4,2,1},{0,81,27,9,3,1},{0,256,64,16,4,1},{0,625,125,25,5,1}}; for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) { if(fabs(c[j][i])>1e-8) { for(int k=1;k<=n;k++) { swap(c[i][k],c[j][k]); } swap(b[i],b[j]); } } for(int j=1;j<=n;j++) { if(i==j) continue; double rate=c[j][i]/c[i][i]; for(int k=i;k<=n;k++) c[j][k]-=c[i][k]*rate; b[j]-=b[i]*rate; } } double m1=b[1]/c[1][1]; double m2=b[2]/c[2][2]; double m3=b[3]/c[3][3]; double m4=b[4]/c[4][4]; ll m; printf("%lf\n",m1); while(~scanf("%lld",&m)) { double ans=m1*pow(m,4)+m2*pow(m,3)+m3*pow(m,2)+m4*m+0.1; //printf("%lf\n%lf\n%lf\n",m1*pow(m,4),m2*pow(m,3),m3*pow(m,2)); ll d=ans; printf("%lld\n",d); } }
先用高斯消元求系数,分别为1/24,6/24,11/24,1/24,0。
然后求出其24的逆元为41666667。
最后得其代码
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<cmath> #include<map> #include<vector> #define ll long long #define mod 1000000007 using namespace std; long long n; long long fpow(long long a,long long p) { long long base=a%mod; long long ans=1; while(p) { if(p&1) ans=ans*base%mod; base=base*base%mod; p=p>>1; } return ans%mod; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%lld",&n); long long ans=(fpow(n,4)+fpow(n,3)*6+fpow(n,2)*11+n%mod*6)%mod; ans=ans*41666667%mod; printf("%lld\n",ans); } }
https://www.cnblogs.com/wrjlinkkkkkk/p/10041144.html
http://xueshu.baidu.com/s?wd=paperuri%3A%281d6cf25a905f1951b577cf287a82e1a3%29&filter=sc_long_sign&tn=SE_xueshusource_2kduw22v&sc_vurl=http%3A%2F%2Fwenku.baidu.com%2Fview%2Fef155ff1a26925c52dc5bf32.html&ie=utf-8&sc_us=12108961739379565888
解释了为什么是四次函数。