HDU 4938 seeing people sorting + Binary Search

Source: Internet
Author: User

Seeing people Time Limit: 6000/3000 MS (Java/others) memory limit: 131072/131072 K (Java/Others)
Total submission (s): 241 accepted submission (s): 61


Problem descriptionthere are two kinds of people.

If person I is the first kind of people, it locates at position (PI, 0) Initially, starts moving at time TI with a constant velocity of (0, V1 ), and then sees every person sits at the line segment (XI, Yi), (XI + WI, Yi), include the two points, where (XI, Yi) is the position of person I at that time and WI is its vision.

If person I is the second kind of people, it locates at position (0, Pi) Initially, starts moving at time TI with a constant velocity of (V2, 0 ), and then sees every person sits at the line segment (XI, Yi), (XI, yi + WI), include the two points, where (XI, Yi) is the position of person I at that time and WI is its vision.

Now given the position of people, Please calculate the number of distinct people every person has finally seen.
Inputthere are multiply test cases.

The first line contains an integer T (t <= 10), indicates the number of cases.

For each test case, the first line contains three integers n, V1, V2 (1 <= N, V1, V2 <= 10 ^ 5 ), indicating the total number of two kinds of people, the speed of the first kind, and the speed of the second kind.

Then comes n lines, the I-th line contains four integers AI, Ti, PI, WI (1 <= AI <= 2, 1 <= Ti, PI, wi <= 10 ^ 5), describing a person, where Ai is the type, Ti is time the person starts moving, Pi is the location and WI is the vision.

It is granted that for the same kind of people, all Ti, Pi are different.
Outputfor each case, You shoshould output "case # K:" First, where k indicates the case number and counts from 1.

Then output n lines, each lines is an integer, indicates the number of distinct people the I-th person finally recorded.
Sample Input
12 1 11 1 1 12 2 2 1
 
Sample output
Case #1:11
 
Authoruestc
Source2014 multi-university training contest 7

Sorting + binary search, code changed for one afternoon, although it took a lot of time, but learned a lot


#include <cmath>#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>using namespace std;const int inf=1e9;int v1,v2,n,T;struct Node{long long t,p,w,kind,rank,cnt;double see_right,see_left;void init(int i){double k=double (v2)/double(v1);cnt=0;rank=i;if(kind==1){see_left=p-t*v2;see_right=see_left+w;}else {see_left=p*k-t*v2;see_right=see_left+w*k;}}bool operator < (const Node& tem) const{return see_left < tem.see_left;}}ans[100010];double data1[100010],data2[100010];bool cmp(Node a,Node b){return a.rank<b.rank;}void init (){scanf("%d %d %d ",&n,&v1,&v2);memset(data1,0,sizeof(data1));memset(data2,0,sizeof(data2));for(int i=0;i<n;i++){scanf("%d %d %d %d",&ans[i].kind,&ans[i].t,&ans[i].p,&ans[i].w);ans[i].init(i);}}void slove(){init();sort(ans,ans+n);int cnt1=0,cnt2=0;for(int i=0;i<n;i++){if(ans[i].kind==1){data1[cnt1++]=ans[i].see_left;}else {data2[cnt2++]=ans[i].see_left;}}data1[cnt1]=inf,data2[cnt2]=inf;for(int i=0;i<n;i++){if(ans[i].kind==2){ans[i].cnt=upper_bound(data1,data1+cnt1+1,ans[i].see_right)-lower_bound(data1,data1+cnt1+1,ans[i].see_left);}else{ans[i].cnt=upper_bound(data2,data2+cnt2+1,ans[i].see_right)-lower_bound(data2,data2+cnt2+1,ans[i].see_left);}}sort(ans,ans+n,cmp);for(int i=0;i<n;i++){printf("%d\n",ans[i].cnt);}}int main (){//freopen("1004.in","r",stdin);//freopen("data.out","w",stdout);int cas=0;scanf("%d",&T);while (T--){printf("Case #%d:\n",++cas);slove();}return 0;}




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.