HihoCoder]#1375 : 沙漠之旅

来源:互联网 发布:个人收支软件免费 编辑:程序博客网 时间:2024/04/25 12:45

华电北风吹
天津大学认知计算与应用重点实验室
2016-09-17

题目链接:
http://hihocoder.com/problemset/problem/1375

题目分析:
用个队列,模拟一下(蛮算)。

参考代码:

#include <iostream>#include <queue>using namespace std;bool Check(queue<pair<int, int>> q){    int current = 0;    while (q.empty()==false)    {        current = current + q.front().first - q.front().second;        q.pop();        if (current < 0)            return false;    }    return true;}int main(){    int n;    int result;    while ((cin >> n) && (n != -1))    {        queue<pair<int, int>> q;        for (int i = 0; i < n; i++)        {            pair<int, int> p;            cin >> p.first >> p.second;            q.push(p);        }        bool flag = false;        for (int i = 0; i < n; i++)        {            if (Check(q))            {                cout << i << endl;                flag = true;                break;            }            q.push(q.front());            q.pop();                        }        if (flag == false)            cout << -1 << endl;    }    return 0;}
0 0