Hdu 1050 Moving Tables

Source: Internet
Author: User

 


First, I will use the conventional greed, and the idea of watching more complete programs as much as possible. But ....... Always WA .... T_T ....
I searched this question on the Internet and found that many people had problems and did not find it. Basically, I used the method of sorting the tail.
In fact, this question is because there are two rows of rooms, so 1 and 2 Share a corridor, one of which cannot be moved when moving.
So I changed my mind later and directly changed it to finding the most overlapping parts in the two orders. (The corridor issue should also be handled during tail sorting .)


AC code:

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace std; struct Node {int s, t; int p ;} a [210]; bool cmp (Node a, Node B) {return. t <B. t;} int main () {int t, n, I, j, tim, ma; scanf ("% d", & t); while (t --) {scanf ("% d", & n); for (I = 0; I <n; I ++) {a [I]. p = 0; scanf ("% d", & a [I]. s, & a [I]. t); a [I]. s = (a [I]. s + 1)/2; // handle the situation where parity is shared by a single walk (this has not been considered, so WA) a [I]. t = (a [I]. t + 1)/2; if (a [I]. s> a [I]. t) // guarantee s <t {j = a [I]. s; a [I]. s = a [I]. t; a [I]. t = j ;}} sort (a, a + n, cmp); ma = 0; for (I = 0; I <n; I ++) {tim = 1; for (j = I + 1; j <n; j ++) {if (a [j]. s <= a [I]. t) // determine whether there is an overlap {tim ++; // Add an overlap} if (tim> ma) {ma = tim ;}} printf ("% d \ n", ma * 10);} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.