【nowcoder】 4th T1 動態點分治

來源:互聯網
上載者:User

標籤:http   coder   break   簡單   nbsp   else   www   tchar   ora   

題目連結:https://www.nowcoder.com/acm/contest/175/A

題目名字嚇死人

std:

太可啪了

一道簡單的類比題。雖然我把題意想錯了。

按照題意類比輸出和繼承。

 

WA 點: 因為資料K範圍在263之內(long long:263-1,unsigned long long int :264-1)

所以會很容易爆

也會爆回[l,r]範圍內 就會WA

如何避免?

首先假設 x 為繼承的值 

那麼每次改變都是x=x*k

如果每次改變的範圍都在r/k的範圍內 那麼就可避免爆

代碼如下:

 1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4  5 int n; 6 ll l,r,k,x; 7 bool check=false; 8  9 ll Read(){10     ll xxx=0,fff=1;char ch=getchar();11     while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘) fff=-1;ch=getchar();}12     while(ch<=‘9‘&&ch>=‘0‘){xxx=(xxx<<3)+(xxx<<1)+ch-‘0‘;ch=getchar();}13     return xxx*fff;14 }15 16 int main(){17     n=Read();18     while(n--){19         l=Read();r=Read();k=Read();20         check=false;21         switch(k){22             case 0: if(l<=0&&r>=0){23                 putchar(‘0‘);putchar(‘ ‘);24                 check=true;25             }26             case 1: if(l<=1&&r>=1){27                 putchar(‘1‘);putchar(‘ ‘);28                 check=true;29                 30             }31             break;32             default:for(x=1;;){33                 if(l<=x&&x<=r) {34                     printf("%lld ",x);35                     check=true;36                 }37                 if(x<=r/k) x*=k;else break;38             }39         }40         if(!check) {41             puts("None.");42         }43         else putchar(‘\n‘);44     }45     return 0;46 }

PE幾次以後才知道puts()自動換行

【nowcoder】 4th T1 動態點分治

聯繫我們

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