hdu 1050 Moving Table

来源:互联网 发布:在哪买淘宝号安全 编辑:程序博客网 时间:2024/05/17 08:24

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1050

很容猜到是用信心,但老是做不对,,抓狂,,郁闷!!!

 首先要注意几点:

1。对数据的预先处理。

对于 (room 2 to room 3 ) and (room 4 to room 6), It's impossible move in once.

when room 2 to roo 3 ,it ocupy space 1 to 4.

So while room 4 to room 6. space 4 will be used by both.It's impossible.安静

 

2。下面就是排序了,按开始位置排序。

 

Game Over!

#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;struct Node {int s, e;bool flag;bool operator <(const Node &elem) const {if(s!=elem.s)return s < elem.s;elsereturn e < elem.e;}} move[209];int main(int argc, char **argv) {//freopen("input.txt","r",stdin);int i, n, times, finished, T;cin >> T;while (T--) {cin >> n;for (i = 0; i < n; ++i) {cin >> move[i].s >> move[i].e;if (move[i].s > move[i].e)swap(move[i].s, move[i].e);if (move[i].s % 2 == 0)move[i].s--;if (move[i].e % 2 != 0)move[i].e++;move[i].flag = true;}sort(move, move + n);times = 0;while (true) {i = 0;while (!(move[i].flag) && i < n)++i;if (i < n) {move[i].flag = false;finished = move[i].e;++times;++i;} elsebreak;while(i<n){if (move[i].flag && finished < move[i].s){move[i].flag = false;finished=move[i].e;}++i;}}cout << 10 * times << endl;}return 0;}


 

原创粉丝点击