Sicily 1443
2014-11-08 20:53
218 查看
题目蛮好理解,就是简单的对队列进行操作。ac后看了别人的代码,发现可以先把每个Job设置成一个struct,里面记录当前的位置和优先级。我直接在while循环里面进行判断了。所以看起来比较冗余。
题目:http://www.soj.me/1443
代码:
题目:http://www.soj.me/1443
代码:
// Copyright <lijiancheng> [2014] // Sicily 1443 #include <iostream> #include <deque> using namespace std; int main () { int testcase; cin >> testcase; while (testcase--) { int n, m, ans = 1; deque<int> q; cin >> n >> m; // 获得第m个位置的priority int prio = 0; for (int i = 0; i < n; i++) { int temp; cin >> temp; q.push_back(temp); if (i == m) prio = temp; } // 每次遍历遍历一遍 找最大 若第一个是最大则直接pop出去,否则进行移位 int pos = m; while (1) { int maxPrio = 0; int maxPos = 0; deque<int>::iterator it = q.begin(); for (int i = 0; it != q.end();i++, it++) { if (*it > maxPrio) { maxPrio = *it; maxPos = i; } } if (maxPos == 0) { if (pos == 0) { cout << ans << endl; break; } else { ans++; q.pop_front(); pos--; } } else { if (pos == 0) { int temp = q.front(); q.pop_front(); q.push_back(temp); pos = q.size()-1; } else { pos--; int temp = q.front(); q.pop_front(); q.push_back(temp); } } } } }
相关文章推荐
- sicily 1443
- POJ 3125 && Sicily 1443 Printer Queue(模拟/队列)
- sicily 1443.Printer Queue
- Sicily 1443
- POJ 3125 && Sicily 1443 Printer Queue(模拟/队列)
- sicily 1443 Printer Queue
- Sicily1443—— Printer Queue
- sicily--1443. Printer Queue
- sicily 1443 Printer Queue
- 这周的一道程序设计题兼sicily1443 Printer Queue题解
- sicily 1443 队列基本操作
- sicily 1443 Printer Queue
- sicily 1443
- Sicily 1443 Printer Queue
- Sicily 1791. Philia's Problem
- Sicily 1031 Campus(单源最短路Dijkstra)
- 中大Sicily分类
- Sicily 1039. Phone Home
- Sicily 1196 Conflict(传递闭包的建立)
- Sicily 1931 卡片游戏