普及組Day1教案

首先自己先注冊(cè)好一個(gè)洛谷Luogu的賬號(hào),接下來(lái)三天都在上面刷題。上課前詢問(wèn)一下學(xué)生們有沒(méi)有在這個(gè)網(wǎng)站上注冊(cè)賬號(hào),如果他們都沒(méi)注冊(cè)你就可以跟他們介紹一下這個(gè)網(wǎng)站,這個(gè)網(wǎng)站上面有很多題,這些題按照涉及的不同算法和不同難度被分類,并且?guī)缀趺康李}目都有題解,非常適合學(xué)OI的同學(xué)在上面刷題,題目刷多了就能提高自己的實(shí)力。

然后,開(kāi)始考察一下學(xué)生的能力。學(xué)生是從海南來(lái)的,剛學(xué)完零基礎(chǔ)的課程,差不多就是僅僅掌握C/C++語(yǔ)法的水平。所以先給他們幾道模擬題,看他們的完成情況如何。有些題目這些學(xué)生可能之前做過(guò),所以我這里準(zhǔn)備了多幾道題,選擇其中1~2道布置給他們即可。在布置給他們之前,先詢問(wèn)“這道題做沒(méi)做過(guò)?”,假如他們說(shuō)做過(guò),你就解釋一下你找的題都是普及組入門的經(jīng)典題,做過(guò)很正常,然后換一道題目給他們。

題目可從下面抽選(基本上都是模擬題,模擬的意思就是按照題目的要求用程序?qū)τ?jì)算過(guò)程進(jìn)行簡(jiǎn)單的模擬,不涉及到其他任何算法或數(shù)據(jù)結(jié)構(gòu)):

  1. Luogu P1055 ISBN號(hào)碼
  2. Luogu P1008 三連擊
  3. Luogu P1206 回文平方數(shù) Palindromic Squares
  4. Luogu P1257 平面上的最接近點(diǎn)對(duì)
  5. Luogu P1328 生活大爆炸版石頭剪刀布

這幾道題目的AC(Accepted)代碼我都附在后面。給他們一題比如最多40分鐘的時(shí)間,如果到這個(gè)時(shí)間還有人沒(méi)做出來(lái),就可以把AC代碼拿出來(lái)講解,講一下代碼每一步在做什么,為什么要這樣做。講解完后讓他們繼續(xù)寫,如果還寫不出來(lái)就幫他們看代碼、改代碼,debug。如果有個(gè)別同學(xué)能力比較強(qiáng),先做出來(lái)了,就安排他自己去做上面列表中的其他題目,不要讓他們閑著沒(méi)事干。

// Luogu P1055 ISBN號(hào)碼
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    char isbn[20];
    scanf("%s", isbn);
    int l = strlen(isbn), s = 0, t = 0;
    for (int i=0; t<9; i++)
        if ('0' <= isbn[i] && isbn[i] <= '9')
            s += (isbn[i] - '0') * (++t);
    s %= 11;
    char c = (s == 10) ? 'X' : ('0'+s);
    if (c == isbn[l-1]) printf("Right\n");
    else {
        isbn[l-1] = c;
        printf("%s\n", isbn);
    }
    return 0;
}
// Luogu P1008 三連擊
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int used[10];
    for (int i=100; i<=333; i++) {
        for (int j=0; j<=9; j++) used[j] = 0;
        for (int j=1; j<=3; j++) {
            used[i*j/100]++;
            used[i*j/10%10]++;
            used[i*j%10]++;
        }
        bool ok = true;
        for (int j=1; j<=9; j++) if (used[j]!=1) ok = false;
        if (ok) printf("%d %d %d\n", i, i*2, i*3);
    }
    return 0;
}
// Luogu P1206 回文平方數(shù) Palindromic Squares
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int B, x[30], x2[30];
    scanf("%d", &B);
    for (int i=1; i<=300; i++) {
        int t = i*i, len = 0, len2 = 0;
        while (t) {
            x2[len2++] = t % B;
            t /= B;
        }
        bool ok = true;
        for (int j=0; j<len2; j++) if (x2[j] != x2[len2-1-j]) ok = false;
        if (ok) {
            t = i;
            while (t) {
                x[len++] = t % B;
                t /= B;
            }
            for (int j=len-1; j>=0; j--) printf("%c", x[j]<10 ? x[j]+'0' : x[j]-10+'A');
            printf(" ");
            for (int j=len2-1; j>=0; j--) printf("%c", x2[j]<10 ? x2[j]+'0' : x2[j]-10+'A');
            printf("\n");
        }
    }
    return 0;
}
// Luogu P1257 平面上的最接近點(diǎn)對(duì)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int n;
double x[10000], y[10000], ans = 99999999999;
int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++) scanf("%lf %lf", &x[i], &y[i]);
    for (int i=0; i<n-1; i++)
        for (int j=i+1; j<n; j++) {
            double dis = sqrt((x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j]) * (y[i]-y[j]));
            if (dis < ans) ans = dis;
        }
    printf("%.4lf\n", ans); // 使用.4lf格式控制符輸出4位小數(shù)
    return 0;
}
// Luogu P1328 生活大爆炸版石頭剪刀布
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int winlist[5][5] = {
    0, -1, 1, 1, -1,
    1, 0, -1, 1, -1,
    -1, 1, 0, -1, 1,
    -1, -1, 1, 0, 1,
    1, 1, -1, -1, 0
};
int n, na, nb, ga[300], gb[300];
int main() {
    scanf("%d %d %d", &n, &na, &nb);
    for (int i=1; i<=na; i++) scanf("%d", &ga[i]);
    for (int i=1; i<=nb; i++) scanf("%d", &gb[i]);
    int ia=0, ib=0, ansa=0, ansb=0;
    for (int i=1; i<=n; i++) {
        ia++;
        ib++;
        if (ia>na) ia=1;
        if (ib>nb) ib=1;
        if (winlist[ga[ia]][gb[ib]]>0) ansa += winlist[ga[ia]][gb[ib]];
        if (winlist[ga[ia]][gb[ib]]<0) ansb -= winlist[ga[ia]][gb[ib]];
    };
    printf("%d %d\n", ansa, ansb);
    return 0;
}

上面這些題目做完,預(yù)期是上午三小時(shí)就過(guò)去了。假如他們提前做完了,就繼續(xù)講后面的內(nèi)容;假如他們沒(méi)做完,就繼續(xù)加快進(jìn)度幫助他們debug把題目做完,或者跟他們說(shuō)為了不耽誤課程進(jìn)度,這幾道題目就先弄到這里為止,今天課程結(jié)束后大家回去自己找時(shí)間繼續(xù)調(diào)試程序,如果有實(shí)在調(diào)試不出來(lái)的就把代碼發(fā)給你,你晚上幫他們?cè)僮屑?xì)看看。課程進(jìn)度可以自己靈活控制,不要太快了把準(zhǔn)備的內(nèi)容講完了,也不要太慢了導(dǎo)致很多內(nèi)容沒(méi)講。加快進(jìn)度的方法是減少做題時(shí)間,盡早開(kāi)始給他們展示講解AC代碼并幫他們debug,減慢進(jìn)度的方法就是多布置幾道題目給他們做。

下午的三小時(shí)課程,主要內(nèi)容是教他們高精度運(yùn)算。一般整數(shù)我們用int或long long存儲(chǔ)進(jìn)行運(yùn)算,高精度運(yùn)算就是用數(shù)組存儲(chǔ)數(shù)字的每一位,實(shí)現(xiàn)運(yùn)算。通過(guò)高精度運(yùn)算我們可以實(shí)現(xiàn)計(jì)算2000位的整數(shù)乘以2000位的整數(shù)的結(jié)果,而直接用int或long long都肯定會(huì)溢出。高精度運(yùn)算一般包括加、乘、除(沒(méi)有減,因?yàn)闇p和加原理類似)。高精度加法最簡(jiǎn)單,乘法中等,除法最難。其中,高精度加法一般為高精加高精,高精度乘法一般分為高精乘低精和高精乘高精(這里的高精指用數(shù)組存儲(chǔ)的數(shù),而低精指普通的用int或long long存儲(chǔ)的數(shù))。

按照他們的能力和課程的時(shí)間,如果他們掌握速度快就可以講完高精度除法,如果速度慢講完高精度加法、乘法就可以了。假如他們之前學(xué)過(guò)高精度也沒(méi)有關(guān)系,下面的題目當(dāng)作對(duì)于他們學(xué)習(xí)情況的檢驗(yàn)。

洛谷上高精度的模板題有:

  1. 高精度加法:Luogu P1601 A+B Problem(高精)
  2. 高精度減法:Luogu P2142 高精度減法
  3. 高精度乘法(高精乘低精):Luogu P1009 階乘之和
// Luogu P1601 A+B Problem(高精)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
char s1[510], s2[510];
int a[510], b[510], c[510];
int main() {
    scanf("%s%s", s1, s2);
    int len1 = strlen(s1), len2 = strlen(s2);
    // 將讀入的字符串反過(guò)來(lái)存成int,高位在右低位在左
    for (int i=0; i<len1; i++) a[i] = s1[len1-1-i] - '0';
    for (int i=0; i<len2; i++) b[i] = s2[len2-1-i] - '0';
    int len = max(len1, len2);
    for (int i=0; i<len; i++) {
        c[i] += (a[i] + b[i]);
        c[i+1] = c[i] / 10;
        c[i] %= 10;
    }
    while (c[len]) {
        c[len+1] = c[len] / 10;
        c[len] %= 10;
        len++;
    }
    for (int i=len-1; i>=0; i--) printf("%d", c[i]);
    printf("\n");
    return 0;
}
// Luogu P1009 階乘之和
// 這是一道涉及高精加高精和高精乘低精的題目
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int S[1000], lens;
int T[200], lent;
int main() {
    int N; scanf("%d", &N);
    T[0] = 1;
    lent = 1;
    for (int i=1; i<=N; i++) {
        for (int j=0; j<lent; j++) T[j] *= i;
        for (int j=0; j<lent; j++) {
            T[j+1] += T[j] / 10;
            T[j] %= 10;
        }
        while (T[lent]) {
            T[lent+1] = T[lent] / 10;
            T[lent] %= 10;
            lent++;
        }
        // 上面代碼算出i的階乘,用數(shù)組T表示
        lens = max(lens, lent);
        for (int j=0; j<lens; j++) S[j] += T[j];
        for (int j=0; j<lens; j++) {
            S[j+1] += S[j] / 10;
            S[j] %= 10;
        }
        while (S[lens]) {
            S[lens+1] = S[lens] / 10;
            S[lens] %= 10;
            lens++;
        }
        // 上面的代碼將T加到S中
    }
    for (int i=lens-1; i>=0; i--) printf("%d", S[i]);
    printf("\n");
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 國(guó)家電網(wǎng)公司企業(yè)標(biāo)準(zhǔn)(Q/GDW)- 面向?qū)ο蟮挠秒娦畔?shù)據(jù)交換協(xié)議 - 報(bào)批稿:20170802 前言: 排版 ...
    庭說(shuō)閱讀 12,514評(píng)論 6 13
  • Win7下如何打開(kāi)DOS控制臺(tái)? a:開(kāi)始--所有程序--附件--命令提示符 b:開(kāi)始--搜索程序和文件--cmd...
    逍遙嘆6閱讀 1,723評(píng)論 4 12
  • 今天哥哥回家后給他把褲子脫了。光著屁股爬到床上,站在妹妹旁邊嘴里發(fā)出噓噓的聲音,說(shuō)尿床上呢。拽下里無(wú)數(shù)次,又自己爬...
    景一夫閱讀 590評(píng)論 0 0
  • 身體感覺(jué)被掏空了 每天好像行尸走肉一樣 做的自己不喜歡的事兒 每個(gè)人的淚點(diǎn)不一樣 工作談不上喜歡 就是感覺(jué)那是我不...
    一只笨烏龜?shù)娜崭兆x閱讀 116評(píng)論 0 0
  • 我陪師傅取經(jīng),九九八十一難,忙著見(jiàn)招拆招。顧不上想,也不想想;顧不上怨,怕怨了會(huì)苦;顧不上苦,怕苦會(huì)刻在臉上。...
    Jennifer_Jin閱讀 185評(píng)論 0 0

友情鏈接更多精彩內(nèi)容