Luck and Love·HDU1823

來源:互聯網
上載者:User

標籤:des   style   blog   http   java   color   

傳送門:http://acm.hdu.edu.cn/showproblem.php?pid=1823

Luck and Love

Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description世界上上最遠的距離不是相隔天涯海角
而是我在你面前
可你卻不知道我愛你
                ―― 張小嫻

前段日子,楓冰葉子給Wiskey做了個徵婚啟事,聘禮達到500萬哦,天哪,可是天文數字了啊,不知多少MM蜂擁而至,頓時萬人空巷,連掃地的大媽都來湊熱鬧來了。―_―|||
由於人數太多,Wiskey實在忙不過來,就把統計的事情全交給了楓冰葉子,自己跑回家休息去了。這可夠楓冰葉子忙的了,他要處理的有兩類事情,一是得接受MM的報名,二是要幫Wiskey尋找符合要求的MM中緣分最高值。  Input本題有多個測試資料,第一個數字M,表示接下來有連續的M個操作,當M=0時處理中止。
接下來是一個操作符C。
當操作符為‘I’時,表示有一個MM報名,後面接著一個整數,H表示身高,兩個浮點數,A表示活潑度,L表示緣分值。 (100<=H<=200, 0.0<=A,L<=100.0)
當操作符為‘Q’時,後面接著四個浮點數,H1,H2表示身高區間,A1,A2表示活潑度區間,輸出符合身高和活潑度要求的MM中的緣分最高值。 (100<=H1,H2<=200, 0.0<=A1,A2<=100.0)
所有輸入的浮點數,均只有一位小數。  Output對於每一次詢問操作,在一行裡面輸出緣分最高值,保留一位小數。
對尋找不到的詢問,輸出-1。  Sample Input8I 160 50.5 60.0I 165 30.0 80.5I 166 10.0 50.0I 170 80.5 77.5Q 150 166 10.0 60.0Q 166 177 10.0 50.0I 166 40.0 99.9Q 166 177 10.0 50.00  Sample Output80.550.099.9  Source HDOJ 2007 Summer Exercise(3)- Hold by Wiskey   Recommend威士忌   |   We have carefully selected several similar problems for you:  1542 1828 1698 2871 1754  做法:又見模板題。。別急。。我等會兒還要再寫一道模板題。。求和的。。注意這題查不到的要輸出-1。。。另外詢問的時候區間x1,x2,y1,y2大小需要自行比較。 Codes:
 1 #include<set> 2 #include<queue> 3 #include<vector> 4 #include<cstdio> 5 #include<cstdlib> 6 #include<cstring> 7 #include<iostream> 8 #include<algorithm> 9 using namespace std;10 const int H = 202;11 const int L = 1002;12 #define Ch1 ((i)<<1)13 #define Ch2 ((Ch1)|1)14 #define For(i,n) for(int i=1;i<=n;i++)15 #define Rep(i,l,r) for(int i=l;i<=r;i++)16 17 struct tnodey{18     short l,r,mid;19     double max;20 };21 22 struct tnodex{23     short l,r,mid;24     tnodey y[L<<2];25 }T[H<<2];26 27 int x,y,n,x1,x2,y1,y2;28 double delta,ty,ty1,ty2;29 30 double Max(double a,double b){return (a>b)?(a):(b);}31 32 void Buildy(int root,int i,int l,int r){33     T[root].y[i].l = l; T[root].y[i].r = r; T[root].y[i].mid = (l+r)>>1;34     T[root].y[i].max = -5;35     if(l==r) return;36     Buildy(root,Ch1,l,T[root].y[i].mid);Buildy(root,Ch2,T[root].y[i].mid+1,r);37 }38 39 void Buildx(int i,int l,int r){40     Buildy(i,1,0,L);41     T[i].l = l; T[i].r = r; T[i].mid = (l+r)>>1;42     if(l==r) return;43     Buildx(Ch1,l,T[i].mid); Buildx(Ch2,T[i].mid+1,r);44 }45 46 void Modifyy(int root,int i,int x,double delta){47     if(T[root].y[i].l==T[root].y[i].r){48         T[root].y[i].max = Max(T[root].y[i].max,delta);49         return;50     } 51     if(x<=T[root].y[i].mid) Modifyy(root,Ch1,x,delta);52     else                    Modifyy(root,Ch2,x,delta);53     T[root].y[i].max = Max(T[root].y[Ch1].max,T[root].y[Ch2].max);54 }55 56 void Modifyx(int i,int x,double delta){57     Modifyy(i,1,y,delta);58     if(T[i].l==T[i].r) return;59     if(x<=T[i].mid) Modifyx(Ch1,x,delta);60     else            Modifyx(Ch2,x,delta);61 }62 63 double queryY(int root,int i,int l,int r){64     if(l<=T[root].y[i].l&&T[root].y[i].r<=r) return T[root].y[i].max;65     if(r<=T[root].y[i].mid)  return queryY(root,Ch1,l,r);else66     if(l>T[root].y[i].mid)   return queryY(root,Ch2,l,r);else67     return Max(queryY(root,Ch1,l,T[root].y[i].mid),queryY(root,Ch2,T[root].y[i].mid+1,r));68 }69 70 double queryX(int i,int l,int r){71     if(l<=T[i].l&&T[i].r<=r) return queryY(i,1,y1,y2);72     if(r<=T[i].mid) return queryX(Ch1,l,r);73     if(l>T[i].mid)  return queryX(Ch2,l,r);74     return Max(queryX(Ch1,l,T[i].mid),queryX(Ch2,T[i].mid+1,r));75 }76 77 int main(){78     scanf("%d",&n);79     while(n){80         Buildx(1,100,H);81         For(i,n){82             char op;83             scanf("\n");scanf("%c",&op);84             if(op==‘I‘) {85                 scanf("%d%lf%lf",&x,&ty,&delta);y = ty*10;86                 Modifyx(1,x,delta);87             }else{88                 scanf("%d%d%lf%lf",&x1,&x2,&ty1,&ty2);y1 = ty1*10; y2 = ty2*10;89                 if(x1>x2) swap(x1,x2); if(y1>y2) swap(y1,y2);90                 double ans = queryX(1,x1,x2);91                 if(ans<0)  puts("-1");92                 else       printf("%.1lf\n",ans);93                 94             }   95         }96         scanf("%d",&n);97     }98     return 0;99 }

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.