連接:https://codeforces.com/contest/1100ios
題意:瀏覽器有 $n$ 個網頁,編號 $1 \sim n$,選擇一個整數 $b$,則關掉全部編號爲 $b + i \cdot k$ 的網頁,其中 $k$ 爲給定的整數,$i$ 爲任意整數。而後,留下的網頁有兩種類型,計算兩種類型的網頁數目差,要求你給出這個差最大能夠是多少。c++
題解:$n$ 的範圍很小,能夠直接純暴力作便可。數組
AC代碼:瀏覽器
#include<bits/stdc++.h> using namespace std; const int maxn=110; int n,k; int type[maxn],del[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin>>n>>k; for(int i=1;i<=n;i++) cin>>type[i]; int ans=0; for(int b=1;b<=k;b++) { memset(del,0,sizeof(int)*(n+3)); for(int i=b;i<=n;i+=k) del[i]=1; int c1=0, c2=0; for(int i=1;i<=n;i++) if(!del[i]) c1+=(type[i]==1), c2+=(type[i]==-1); ans=max(ans,abs(c1-c2)); } cout<<ans<<endl; }
題意:有一個「問題池」,每次都想一個新問題,估計其難度爲 $x (1 \le x \le n)$,把這個問題扔進問題池,若是問題池內的問題正好能搞出一套難度係數爲 $1 \sim n$ 的 $n$ 道題,就把他們所有取出來。對每次想出來的新問題,肯定其扔進池中後,可否產生一套題。ui
題解1:不難知道,用一個數組 $c[1:n]$ 存儲每一個難度的題目數,再用一個變量 $cnt$ 記錄有多少個難度上是有題目的。若是產生了一套題目,必然是某一個難度的題的數目從 $0$ 變成了 $1$。這樣作是 $O(m)$ 的時間複雜度。spa
AC代碼:code
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+5; int n,m; int cnt,c[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin>>n>>m; cnt=0; for(int i=1,p;i<=m;i++) { cin>>p; c[p]++; if(c[p]==1) { cnt++; if(cnt==n) { cout<<1; for(int k=1;k<=n;k++) if((--c[k])==0) cnt--; } else cout<<0; } else cout<<0; } }
題解2:無腦上線段樹,單點修改、區間查詢,若是產生了一套題目,就暴力的對每一個難度點上都減去 $1$,時間複雜度是 $O(mlogn)$(由於最多產生 $O(m/n)$ 套題目)。blog
AC代碼:ci
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+5; int n,m; int cnt; #define ls (rt<<1) #define rs (rt<<1|1) struct Node{ int l,r; int val,ok; }o[maxn<<2]; void pushup(int rt) { o[rt].val=o[ls].val+o[rs].val; o[rt].ok=o[ls].ok&o[rs].ok; } void build(int rt,int l,int r) { o[rt].l=l, o[rt].r=r; if(l==r) { o[rt].val=o[rt].ok=0; return; } int mid=(l+r)>>1; build(ls,l,mid), build(rs,mid+1,r); pushup(rt); } void update(int rt,int pos,int val) { if(o[rt].l==o[rt].r) { o[rt].val+=val; o[rt].ok=o[rt].val>0; return; } int mid=(o[rt].l+o[rt].r)>>1; pos<=mid?update(ls,pos,val):update(rs,pos,val); pushup(rt); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin>>n>>m; build(1,1,n); cnt=0; for(int i=1,p;i<=m;i++) { cin>>p; update(1,p,1); if(o[1].ok) { cout<<1; for(int k=1;k<=n;k++) update(1,k,-1); } else cout<<0; } }
題意:給出一個圓,半徑爲 $r$,其周圍有 $n$ 個徹底相同的圓將其包圍,這 $n$ 個圓分別和中心圓互相緊貼,且這 $n$ 個圓構成一個環,環上任意兩個相鄰的圓也都是緊貼的。要求你求出這 $n$ 個圓的半徑 $R$。get
題解:$\sin(\frac{\pi}{n}) \cdot (R+r) = R$。
AC代碼:
#include<bits/stdc++.h> using namespace std; const double pi=acos(-1); int n; double r,R; int main() { cin>>n>>r; R=sin(pi/n)*r; R/=(1-sin(pi/n)); printf("%.8f\n",R); }
題意: