Codeforces 15A Cottage Village

Source: Internet
Author: User

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

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.