uva 12086 - Potentiometers

來源:互聯網
上載者:User

標籤:

是一道樹狀數組的模板題

 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <iostream> 5 int b[300000],a[300000],n; 6 int lowbit(int x) 7 { 8     return x&(-x); 9 }10 int sum(int x)11 {12     int sum=0;13     while(x>0)14     {15         sum=sum+b[x];16         x=x-lowbit(x);17     }18     return sum;19 }20 void add(int i,int x)21 {22     while(i<=n)23     {24         b[i]=b[i]+x;25         i=i+lowbit(i);26     }27 }28 int main()29 {30     int t=1;31     int cx=0;32     while(scanf("%d",&n)!=EOF&&n)33     {34         if(cx)35             puts("");36         memset(b,0,sizeof(b));37         int  d,e,x;38         char c[10];39         for(int i=1; i<=n; i++)40         {41             scanf("%d",&a[i]);42             add(i,a[i]);43         }44         printf("Case %d:\n",t++);45         while(1)46         {47             scanf("%s",c);48             if(strcmp(c,"END")==0)49                 break;50             if(c[0]==‘M‘)51             {52                 scanf("%d%d",&d,&e);53                 printf("%d\n",sum(e)-sum(d-1));54             }55             if(c[0]==‘S‘)56             {57                 scanf("%d%d",&d,&e);58                 x=e-a[d];59                 a[d]=e;60                 add(d,x);61             }62         }63         cx=n;64     }65     return 0;66 }

 

     

       A potentiometer, or potmeter for short, is an electronic device with a variable electric resistance. Ithas two terminals and some kind of control mechanism (often a dial, a wheel or a slide) with which theresistance between the terminals can be adjusted from zero (no resistance) to some maximum value.Resistance is measured in Ohms, and when two or more resistors are connected in series (one after theother, in a row), the total resistance of the array is the sum of the resistances of the individual resistors.In this problem we will consider an array ofNpotmeters, numbered 1 toNfrom left to right. Theleft terminal of some potmeter numberedxis connected to the right terminal of potmeterx

uva 12086 - Potentiometers

聯繫我們

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