Title Link: Http://codeforces.com/problemset/problem/15/A
Test instructions: The x-axis has already covered N-seat houses (the house is square and centered on the x-axis). The side of the house is long parallel axes, and the house cannot overlap, but it can be adjacent (sharing one side). Given the edge length and center location, ask to cover another side length as T House, and to be adjacent to other houses, there are several possible locations.
Idea: Violence, which is considered to cover the house between every two houses and at the most border of two. (My practice is to directly mark the place that is already occupied, and then see if the house can cover both sides). Note that the middle distance of two houses is exactly t when you can only cover one, >t two seats.
Because he gave the coordinates is the middle point position, if the side length is odd is not good to deal with, so I have to expand the edge twice times, so as to avoid the emergence of 0.5.
Code:
intMain () {intn,t,a,s,mx=-1001, mn=1001, TT,AA,BB; Map<int,int>Vis; scanf ("%d%d",&n,&t); for(intI=0; i<n;i++) {scanf ("%d%d",&a,&TT); AA=a*2-tt; BB=a*2+tt; for(intj=aa;j<=bb;j++) {Vis[j]=1; if(j>mx) MX=J; if(j<mn) MN=J; }} t*=2; inttx=0, sum=0; for(inti=mn;i<=mx;i++) { if(vis[i]==0) {TX++; } Else{TX++; if(tx>t) sum+=2; Else if(tx==t) sum++; TX=0; } } if(tx>t) sum+=2; Else if(tx==t) sum++; T=0; Sum+=2; printf ("%d\n", sum);}View Code
Codeforces 15A Cottage Village