Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
123283 周民苡 火车上的人数 C++ Accepted 1 MS 280 KB 505 2025-06-28 17:35:16

Tests(5/5):


Code:

#include<bits/stdc++.h> using namespace std; int main() { int a,n,m,x; cin>>a>>n>>m>>x; int up[16]= {0}; int down[16]= {0}; int people[16]= {0}; up[1]=a; down[1]=0; people[1]=a; for (int b=0; b<=m; b++) { up[2]=b; down[2]=b; people[2]=a; for (int i=3; i<n;i++) { up[i]=up[i-1]+up[i-2]; down[i]=up[i-1]; people[i]=people[i-1]+up[i]-down[i]; } if (people[n-1]==m) { cout<<people[x]<<endl; return 0; } } cout<<"No answer."; return 0; }