Simple POJ 1195 Mobile phones, a two-dimensional tree-like array.

Source: Internet
Author: User

Description

Suppose the fourth generation mobile phone base stations in the Tampere area operate as follows. The area was divided into squares. The squares form an s * s matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone was moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row And the column of the Matrix.

Write a program, which receives these reports and answers queries on the current total number of active mobile phones I    N any rectangle-shaped area. A two-dimensional tree-like array of bare topics, but note that the coordinates should be added one, because starting from 0. The code is as follows:
//The ━━━━━━ of gods and Beasts ━━━━━━//┏┓┏┓//┏┛┻━━━━━━━┛┻┓//┃┃//┃━┃//████━████┃//┃┃//┃┻┃//┃┃//┗━┓┏━┛//┃┃//┃┃//┃┗━━━┓//┃┣┓//┃┏┛//┗┓┓┏━━━━━┳┓┏┛//┃┫┫┃┫┫//┗┻┛┗┻┛////━━━━━━ Feel the ━━━━━━ of Meng Meng//author:whywhy//Created time:2015 July 17 Friday 14:44 13 seconds//File name:1195.cpp#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<time.h>using namespacestd;Const intmaxn=1100;intC[MAXN][MAXN];intN;inlineintLowbit (intx) {    returnx& (-x);}voidAddintXintYintd) {    intT;  while(x<=N) {T=y;  while(t<=N) {c[x][t]+=D; T+=lowbit (t); } x+=lowbit (x); }}intQueryintXinty) {    intret=0; intT;  while(x>0) {T=y;  while(t>0) {ret+=C[x][t]; T-=lowbit (t); } x-=lowbit (x); }    returnret;}intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);    inta,b,c,d,e;  while(1) {scanf ("%d",&a); if(a==1) {scanf (" %d%d%d",&b,&c,&d); Add (b+1, c+1, D); }        Else if(a==2) {scanf ("%d %d%d%d",&b,&c,&d,&e); printf ("%d\n", Query (d+1, e+1)-query (d+1, c)-query (b,e+1)+query (b,c)); }        Else if(a==0) {scanf ("%d",&N); memset (C,0,sizeof(C)); }        Else             Break; }        return 0;}
View Code

Simple POJ 1195 Mobile phones, a two-dimensional tree-like array.

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.