1042-lots of Sunlight
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=3483
Idea: For a given floor, enumerate the maximum slope of the left and right.
Atan (k)/pi represents the percentage of the time taken, noting that the end time is calculated with Pi-atan (k).
I actually returned the first place after the submission.
Complete code:
/*0.118s*/#include <bits/stdc++.h> using namespace std;
Const double EPS = 1e-8; const int BEGIN = (5 * + panax) *, end = (18 * 60 + 17) * 60;
SEC int m[105], d[105], pos[105];
int main () {int n, cas = 0, id, Floor, W, H, I, beg, end;
Double left, right;
while (scanf ("%d", &n), N) {scanf ("%d%d", &w, &h);
for (i = 1; i < n; ++i) {scanf ("%d%d", &m[i), &d[i]);
Pos[i + 1] = Pos[i] + W + d[i];
} scanf ("%d", &m[n]);
printf ("Apartment Complex:%d\n", ++cas); while (scanf ("%d", &floor), Floor) {id = Floor%, Floor/=-MB, left = Righ
t = 0.0; if (ID < 1 | | | ID > N | | Floor < 1 | |
Floor > M[id]) {printf ("Apartment%d:does not exist\n", Floor * + ID);
Continue }
for (i = 1; i < ID; ++i) if (M[i] >= Floor) left = Max (left, D
ouble) ((M[i]-Floor + 1) * H)/(Pos[id]-pos[i]-W);///height difference/distance for (i = ID + 1; I <= n; ++i) if (M[i] >= Floor) right = max (right, double) ((m[i)-Floor + 1) * H)/(pos[i)-Pos
[ID]-W)); Beg = (int) (Atan (left) * (End-begin)/M_pi + EPS) + BEGIN;
Pay attention to +eps!
end = (int) (M_pi-atan (right) * (End-begin)/M_pi + EPS) + BEGIN; printf ("Apartment%d:%02d:%02d:%02d-%02d:%02d:%02d\n", Floor * + ID, beg/3600, beg/60% 60
, Beg, end/3600, END/60, end% 60);
} return 0; }
Author: csdn Blog Synapse7
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/