UVa 1042 Lots of Sunlight: enumerations & Optimal slope

Source: Internet
Author: User
Tags cas printf time limit

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/

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.