hdu,hdukmp

來源:互聯網
上載者:User

hdu,hdukmp

題意:N 幢樓排成一列(1<=N<=10^5),各樓有橫座標 xi(1<=xi<=10^7) 以及高度 hi(1<=hi<=10^7),在各樓之間的Q個位置(1<=Q<=10^5),問這些位置可以仰望天空的夾角是多少度。

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=5033

——>>將樓和人的位置一起按 x 排序。。

      從左往右掃,單調棧維護斜率小的。。

      從右往左掃,單調棧維護斜率大的。。

#include <cstdio>#include <algorithm>#include <cmath>using std::sort;const double EPS = 1e-8;const double PI = acos(-1.0);const int MAXN = 100000 + 10;int N, Q, kase;double L[MAXN], R[MAXN];int Dcmp(double x){    if (fabs(x) < EPS) return 0;    return x > 0 ? 1 : -1;}struct BUILD{    double x;    double h;    int id;    bool operator < (const BUILD& e) const    {        return Dcmp(x - e.x) < 0;    }} b[MAXN << 1];double Slope(const BUILD& a, const BUILD& b){    return (b.h - a.h) / (b.x - a.x);}int st[MAXN];struct MS{    int top;    MS(): top(0) {}    void Push(int id)    {        st[top++] = id;    }    void PopMax(const BUILD* b, const int& id)    {        while (top >= 2 && Dcmp(Slope(b[id], b[st[top - 1]]) - Slope(b[id], b[st[top - 2]])) >= 0)        {            --top;        }    }    void PopMin(const BUILD* b, const int& id)    {        while (top >= 2 && Dcmp(Slope(b[id], b[st[top - 1]]) - Slope(b[id], b[st[top - 2]])) <= 0)        {            --top;        }    }    int Top()    {        return st[top - 1];    }};void Read(){    scanf("%d", &N);    for (int i = 1; i <= N; ++i)    {        scanf("%lf%lf", &b[i].x, &b[i].h);        b[i].id = 0;    }    scanf("%d", &Q);    for (int i = 1; i <= Q; ++i)    {        scanf("%lf", &b[i + N].x);        b[i + N].id = i;        b[i + N].h = 0.0;    }}void Init(){    sort(b + 1, b + 1 + N + Q);}void GetLeft(){    MS ms;    for (int i = 1; i <= N + Q; ++i)    {        if (!b[i].id)        {            ms.PopMax(b, i);            ms.Push(i);        }        else        {            ms.PopMax(b, i);            int j = ms.Top();            L[b[i].id] = b[j].h / (b[i].x - b[j].x);        }    }}void GetRight(){    MS ms;    for (int i = N + Q; i >= 1; --i)    {        if (!b[i].id)        {            ms.PopMin(b, i);            ms.Push(i);        }        else        {            ms.PopMin(b, i);            int j = ms.Top();            R[b[i].id] = b[j].h / (b[j].x - b[i].x);        }    }}void Output(){    printf("Case #%d:\n", ++kase);    for (int i = 1; i <= Q; ++i)    {        printf("%.10f\n", 180.0 / PI * (PI - atan(L[i]) - atan(R[i])));    }}int main(){    int T;    kase = 0;    scanf("%d", &T);    while (T--)    {        Read();        Init();        GetLeft();        GetRight();        Output();    }    return 0;}



hdu acm 2032

我發我的ac代碼給你看吧,肯定是輸出時多了什麼空格什麼的,好好看看吧,加油
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a[31][31];
int i,j,k;
for(i=1;i<=30;i++)
a[i][1]=a[i][i]=1;
if(n==1)printf("1\n");
if(n>=2)printf("1\n1 1\n");
for(i=3;i<=n;i++)
{
printf("1 ");
for(j=2;j<i;j++)
{
a[i][j]=a[i-1][j]+a[i-1][j-1];
printf("%d ",a[i][j]);
}
printf("%d\n",a[i][i]);
}
printf("\n");
}
}
 
HDU2001怎做

#include <stdio.h>
#include <math.h>
int main()
{
double x1,y1,x2,y2;
while(EOF != scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2))
{
printf("%.2lf\n",sqrt(pow(x1-x2,2)+pow(y1-y2,2)));
}
return 0;
}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.