【2017.10.30】noip賽前集訓 | T1 軍訓排隊【模擬】
阿新 • • 發佈:2017-10-31
printf 們的 amp can ast 老師 truct 什麽 struct
T1 軍訓排隊
【題目描述】
今年招生招了 n 個班。每個班的小學弟小學妹,在操場上面向主席臺站成了一列。各個班的新生 隨便站成一列,因為他們不懂事,所以也沒有間隔一個固定的距離也沒有按照一定的順序(保 證沒有兩個人在同一個位置)。你和你的好基友便坐在主席臺上一邊喝水一邊看著他們。這 是一個帶有升降功能的主席臺,它的高度由你決定。當然,這個主席臺的高度不能小於 0。 好基友:根據可靠消息,第 i 個班有 ai 個人。為什麽我們看不全這麽多人? 你:你讀書讀傻了吧。他們身高不一樣,擋住了唄。 好基友:好哥們~這裏是他們的體檢表。第 i 個班有 ai 份,按照學號從 1 到 ai 整理好 了,上面有他們的身高體重三圍。老師也上報了目前大家所在的位置。你能不能立刻告訴我 從我們現在的角度來看可以看見多少人? 為了解決好基友的問題,你需要寫一個程序。
【數據範圍】
對於 60%的數據, n≤ 5,ai≤ 1000,0≤ xj≤ 1W,0<hj≤1W,0<T≤ 10,0<A≤ 10;
對於 100%的數據, n ≤ 5,ai≤ 3000,0≤ xj≤ 10W,0<hj≤ 10W,0<T≤ 10,0<A≤ 10
【題解】
只要按照位置從近到遠排個序,然後計算每個人的影子最遠到哪裏。
如果後一個人的影子沒有被前一個人的影子擋住,就能夠看見他。
反之則不能,此時我們只要取最長的那個影子然後繼續比較即可。
#include <cstdio> #include <algorithm> const int MAXN = 3000+ 7; int n, m, ans; double a, b, i; char ch; struct Node { double high, from, next; bool operator < (Node d) { return from < d.from; } } node[MAXN]; int main() { freopen("profit.in", "r", stdin); freopen("profit.out", "w", stdout); scanf("%d", &n); while (n--) { for (int i = 1; i <= n; i++) node[i].from = 0, node[i].high = 0, node[i].next = 0; scanf("%d", &m); for (int i = 1; i <= m; i++) scanf("%lf%lf", &node[i].from, &node[i].high); scanf("%lf%c%lf", &a, &ch, &b); for (int i = 1; i <= m; i++) node[i].next = node[i].from + node[i].high / a * b; std::sort(node + 1, node + m + 1); ans = 0; int last = node[1].next; for (int i = 2; i <= m; i++) { if (node[i].next <= last) continue; ans++; last = node[i].next; } printf("%d\n", ans + 1); } return 0; }
【2017.10.30】noip賽前集訓 | T1 軍訓排隊【模擬】