您的位置:首页 > 其它

Noip 1998 洛谷P1011 车站 - 模拟

2017-10-31 17:12 267 查看
挺好玩的一道题。。。需要知道第二站到底上了多少人,可以枚举这个人数,然后模拟过去,看最后一站下车的人数是否等于m,求出这个人数后再模拟一次就好了

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define debug(x) cerr << #x << "=" << x << endl;
const int MAXN = 2000 + 10;
int stat[MAXN], train[MAXN], a,n,m,x;
void init() {
memset(stat, 0, sizeof(stat));
memset(train, 0, sizeof(train));
}
int guess() {
int tempa;
bool flg = true;
for(int i=1; i<=m; i++) {
init();
stat[1] = a;
stat[2] = i;
train[1] = train[2] = a;
for(int o=3; o<n; o++) {
stat[o] = stat[o-1] + stat[o-2];
train[o] = stat[o] + train[o-1];
train[o] -= stat[o-1];
}
if(train[n-1] == m) {
flg = true;
tempa = i;

4000
break;
}
}
if(flg) return tempa;
}
int main() {
cin >> a >> n >> m >> x;
int ta = guess();
init();
stat[1] = a;
stat[2] = ta;
train[1] = a;
train[2] = a;
for(int i=3; i<=n; i++) {
stat[i] = stat[i-1] + stat[i-2];
train[i] = stat[i] + train[i-1];
train[i] -= stat[i-1];
}
cout << train[x];
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: