9.29考試總結

來源:互聯網
上載者:User

標籤:int   name   枚舉   ++   using   操作   lower   mes   首碼和   

9.29考試總結P2390 地標訪問

一道玄學水題。其實不難。就是二分太容易出問題了。不好調試233

所以學到了系統函數 ——

lower_bound(add, add + n + 1, x) - add;

因為傳回值好像是一個地址,所以減去數組add[0]就可以直接得到位置

這個二分最後被我改成了暴力枚舉

從負數地標位置開始,也可以很好的將全部情況都枚舉出來

核心代碼:

for (int i=1; i<=n; ++i)    {        if (add[i] >= 0) break;        int x = t - abs(add[i]) >> 1;        int y = t - 2 * abs(add[i]);        int a = lower_bound(add, add + n + 1, x) - add;        int b = lower_bound(add, add + n + 1, y) - add;        ans = max(ans, max(a - i + pd, b - i + pd));    }
P2532 樹屋階梯

卡特蘭數(聽說是一個裸題)
f(n)=((n+2)(n+3)...(n+n))/(123...*n);

公式是這個,但是會發現有加法,減法,乘法,除法。又要用高精度,除法就很不友好了。

但是可以發現分子和分母可以抵消掉一部分,就可以變成只需要高精乘單精。

結構體封裝大發好!

#include<bits/stdc++.h>#define IL inline#define open(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);using namespace std;typedef long long ll;typedef unsigned long long ull;const int N = 510;int n, a[N], b[N];struct date{    int l, num[N*10];        date operator * (const int x)    {        date p = {0};        int r = 0, m = l;        for (int i=1; i<=l; ++i)        {            r += num[i] * x;            p.num[i] = r % 10;            r /= 10;        }        while (r)        {            p.num[++m] = r % 10;            r /= 10;        }        while (!p.num[m]) --m;        p.l = m;        return p;    }        void out()    {        for (int i=l; i>=1; --i)            printf("%d", num[i]);        printf("\n");    }}ans;IL int gcd(int, int);int main(){//  open("tab");    std::ios::sync_with_stdio(false);    cin >> n;    for(int i=2; i<=n; i++)    {        a[i-1] = n + i;        b[i-1] = i;    }        for(int i=1; i<n; i++)        for(int j=1; j<n; j++)        {            if(b[j] == 1) continue;            int g = gcd (a[i],b[j]);            if (g != 1)                a[i] /=g , b[j] /= g;            if(a[i] == 1) break;        }          ans.l = ans.num[1] = 1;        for(int i=1; i<n; i++)    {        if(a[i] == 1) continue;        ans = ans * a[i];    }    ans.out();    return 0;}int gcd (int x, int y){    if (!y) return x;    return gcd(y, x % y);}

實際上推出了這個公式,再考慮到將高精度除法去掉以後就不是特別難了。

P2804 神秘數字

我覺得平均數直接用平均數去減每一個數來直接觀察是否滿足好像小學就會用.....可是能.....感覺我沒有學過數學

實際上這個看起來很可怕的題目可以通過預先處理,直接減去m,然後首碼和一下,就可以得出區間和要大於0才能保證區間內的平均數大於m

sum[j]-sum[i-1]>0 => sum[j] > sum[i-1];

然後為什麼不試試神奇的歸併排序來求這個序列呢?

void merge (int l, int mid, int r){    int p1 = l, p2 = mid + 1, k = l - 1;    while(p1 <= mid && p2 <= r)    {        if(sum[p1] < sum[p2])        {            ans += (mid - p1 + 1);            ans %= mod;            temp[++k] = sum[p2];            p2++;        }        else if(sum[p1] >= sum[p2])        {            temp[++k] = sum[p1];            p1++;        }    }    while(p1<=mid) temp[++k] = sum[p1++];    while(p2<=r) temp[++k] = sum[p2++];    for(int i=l; i<=r; i++)        sum[i] = temp[i];}

歸併的最後合并的操作。順手就求出了ans.....還真是方便(話說我還不怎麼記得敲歸併....看來還是要好好補補)

P1221 最多因子數

神仙題,等我改出來再填坑吧。

提前祝大家國慶節過的愉快~

9.29考試總結

聯繫我們

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