1 条题解

  • 0
    @ 2023-6-11 12:20:40

    C :

    #include<stdio.h>
    #define min(a,b)	(a<b?a:b)
    int n;
    int a,b,c,x[100010];
    long long f[100010];
    int main()
    {
    	scanf("%d %d %d %d",&n,&a,&b,&c);
    	for(int i=1;i<=n;i++)
    	{
    		int tmp=((long long)a*i*i+b*i+c)%20000;
        	x[i]=tmp-10000;
    	}
    	f[n]=x[n];
    	for(int i=n-1;i>=0;i--)
    	f[i]=x[i]+min(f[i+1],f[i+2]);
    	printf("%lld",f[0]);
    	return 0;
    } 
    

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int x[100010],n,A,B,C;
    int main(){
    	cin>>n>>A>>B>>C;
    	for (int i = 1; i <= n; i++){
        	int tmp = ((long long)A * i * i + B * i + C) % 20000;
        	x[i] = tmp - 10000;
        } 
        for (int i = 2; i <= n+1; i++){
        	x[i] = min(x[i-1],x[i-2]) + x[i];
        }
        cout<<x[n+1];
    	return 0;
    }
    
    
    • 1

    信息

    ID
    2548
    时间
    1000ms
    内存
    16MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者