2017百度之星初赛a

来源:互联网 发布:淘宝联盟网页版怎么用 编辑:程序博客网 时间:2024/05/19 23:04

题目链接

01:http://acm.hdu.edu.cn/showproblem.php?pid=6108
02:http://acm.hdu.edu.cn/showproblem.php?pid=6109
03:http://acm.hdu.edu.cn/showproblem.php?pid=6110
04:http://acm.hdu.edu.cn/showproblem.php?pid=6111
05:http://acm.hdu.edu.cn/showproblem.php?pid=6112
06:http://acm.hdu.edu.cn/showproblem.php?pid=6113


一些题解


01 小C的倍数问题

 这题的意思是给定一个n进制问在这个n进制的情况下有多少个数让它的倍数每一位加起来是它的倍数。
 可以发现n - 1必然满足关系,而n - 1的因数也肯定满足关系。

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef __int64 LL;int main(){    int t;    scanf("%d", &t);    while(t--)    {        LL p;        scanf("%I64d", &p);        LL ans = 1;        LL ls = p - 1;        for(LL i = 2;i * i <= ls;i++)        {            if(ls % i == 0)            {                LL lsans = 0;                while(ls % i == 0)                {                    lsans++;                    ls /= i;                }                ans *= lsans + 1;            }        }        if(ls > 1)            ans *= 2;        printf("%d\n", ans);    }    return 0;}

05 今夕何夕

 知道某年某月某日问之后最近的哪一年的该日期的星期和这一天一样。
 由于知道365 % 7 == 1所以当前年不是闰年的年份就+1;如果当前年是闰年而且月数大于2那么可以知道多经过了一天,那么就+2;如果当前年的前一年是闰年而且月数小于2那么上一年加的时候没有多经过一天,而当前年多经过了一年所以就+2其他情况就+1。
 这道题要注意不能特判闰年且是2月29号就加28因为可能两个闰年之间之隔不是4年,这种情况的数据在最后。

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int check(int n){    if (n%4==0 && n%100!=0) return 1;    if (n%400==0) return 1;    return 0;}int main(){    //freopen("in.txt", "r", stdin);    //freopen("out.txt", "w", stdout);    int t;    scanf("%d", &t);    while(t--){        int y, m, d;        char ls;        scanf("%d-%d-%d", &y, &m, &d);        int ans = 0;        int i;        for(i = y + 1;;i++)        {            if(check(i)&&m <= 2)            {                ans += 1;            }            else if(check(i - 1)&&m <= 2)            {                ans += 2;            }            else if(check(i)&&m > 2)                ans += 2;            else                ans += 1;            ans %= 7;            if(m == 2&&d == 29){                if(check(i)&&ans == 0)                    break;            }            else if(ans == 0)                break;        }        printf("%d\n", i);    }    return 0;}

 以下数据中间隔着不是4年一次的闰年,即相隔不为28年

72 112   76 116   80 120   84 124   88 128   92 104   96 108   172 212   176 216   180 220   184 224   188 228   192 204   196 208   272 312   276 316   280 320   284 324   288 328   292 304   296 308   472 512   476 516   480 520   484 524   488 528   492 504   496 508   572 612   576 616   580 620   584 624   588 628   592 604   596 608   672 712   676 716   680 720   684 724   688 728   692 704   696 708   872 912   876 916   880 920   884 924   888 928   892 904   896 908   972 1012   976 1016   980 1020   984 1024   988 1028   992 1004   996 1008   1072 1112   1076 1116   1080 1120   1084 1124   1088 1128   1092 1104   1096 1108   1272 1312   1276 1316   1280 1320   1284 1324   1288 1328   1292 1304   1296 1308   1372 1412   1376 1416   1380 1420   1384 1424   1388 1428   1392 1404   1396 1408   1472 1512   1476 1516   1480 1520   1484 1524   1488 1528   1492 1504   1496 1508   1672 1712   1676 1716   1680 1720   1684 1724   1688 1728   1692 1704   1696 1708   1772 1812   1776 1816   1780 1820   1784 1824   1788 1828   1792 1804   1796 1808   1872 1912   1876 1916   1880 1920   1884 1924   1888 1928   1892 1904   1896 1908   2072 2112   2076 2116   2080 2120   2084 2124   2088 2128   2092 2104   2096 2108   2172 2212   2176 2216   2180 2220   2184 2224   2188 2228   2192 2204   2196 2208   2272 2312   2276 2316   2280 2320   2284 2324   2288 2328   2292 2304   2296 2308   2472 2512   2476 2516   2480 2520   2484 2524   2488 2528   2492 2504   2496 2508   2572 2612   2576 2616   2580 2620   2584 2624   2588 2628   2592 2604   2596 2608   2672 2712   2676 2716   2680 2720   2684 2724   2688 2728   2692 2704   2696 2708   2872 2912   2876 2916   2880 2920   2884 2924   2888 2928   2892 2904   2896 2908   2972 3012   2976 3016   2980 3020   2984 3024   2988 3028   2992 3004   2996 3008   3072 3112   3076 3116   3080 3120   3084 3124   3088 3128   3092 3104   3096 3108   3272 3312   3276 3316   3280 3320   3284 3324   3288 3328   3292 3304   3296 3308   3372 3412   3376 3416   3380 3420   3384 3424   3388 3428   3392 3404   3396 3408   3472 3512   3476 3516   3480 3520   3484 3524   3488 3528   3492 3504   3496 3508   3672 3712   3676 3716   3680 3720   3684 3724   3688 3728   3692 3704   3696 3708   3772 3812   3776 3816   3780 3820   3784 3824   3788 3828   3792 3804   3796 3808   3872 3912   3876 3916   3880 3920   3884 3924   3888 3928   3892 3904   3896 3908   4072 4112   4076 4116   4080 4120   4084 4124   4088 4128   4092 4104   4096 4108   4172 4212   4176 4216   4180 4220   4184 4224   4188 4228   4192 4204   4196 4208   4272 4312   4276 4316   4280 4320   4284 4324   4288 4328   4292 4304   4296 4308   4472 4512   4476 4516   4480 4520   4484 4524   4488 4528   4492 4504   4496 4508   4572 4612   4576 4616   4580 4620   4584 4624   4588 4628   4592 4604   4596 4608   4672 4712   4676 4716   4680 4720   4684 4724   4688 4728   4692 4704   4696 4708   4872 4912   4876 4916   4880 4920   4884 4924   4888 4928   4892 4904   4896 4908   4972 5012   4976 5016   4980 5020   4984 5024   4988 5028   4992 5004   4996 5008   5072 5112   5076 5116   5080 5120   5084 5124   5088 5128   5092 5104   5096 5108   5272 5312   5276 5316   5280 5320   5284 5324   5288 5328   5292 5304   5296 5308   5372 5412   5376 5416   5380 5420   5384 5424   5388 5428   5392 5404   5396 5408   5472 5512   5476 5516   5480 5520   5484 5524   5488 5528   5492 5504   5496 5508   5672 5712   5676 5716   5680 5720   5684 5724   5688 5728   5692 5704   5696 5708   5772 5812   5776 5816   5780 5820   5784 5824   5788 5828   5792 5804   5796 5808   5872 5912   5876 5916   5880 5920   5884 5924   5888 5928   5892 5904   5896 5908   6072 6112   6076 6116   6080 6120   6084 6124   6088 6128   6092 6104   6096 6108   6172 6212   6176 6216   6180 6220   6184 6224   6188 6228   6192 6204   6196 6208   6272 6312   6276 6316   6280 6320   6284 6324   6288 6328   6292 6304   6296 6308   6472 6512   6476 6516   6480 6520   6484 6524   6488 6528   6492 6504   6496 6508   6572 6612   6576 6616   6580 6620   6584 6624   6588 6628   6592 6604   6596 6608   6672 6712   6676 6716   6680 6720   6684 6724   6688 6728   6692 6704   6696 6708   6872 6912   6876 6916   6880 6920   6884 6924   6888 6928   6892 6904   6896 6908   6972 7012   6976 7016   6980 7020   6984 7024   6988 7028   6992 7004   6996 7008   7072 7112   7076 7116   7080 7120   7084 7124   7088 7128   7092 7104   7096 7108   7272 7312   7276 7316   7280 7320   7284 7324   7288 7328   7292 7304   7296 7308   7372 7412   7376 7416   7380 7420   7384 7424   7388 7428   7392 7404   7396 7408   7472 7512   7476 7516   7480 7520   7484 7524   7488 7528   7492 7504   7496 7508   7672 7712   7676 7716   7680 7720   7684 7724   7688 7728   7692 7704   7696 7708   7772 7812   7776 7816   7780 7820   7784 7824   7788 7828   7792 7804   7796 7808   7872 7912   7876 7916   7880 7920   7884 7924   7888 7928   7892 7904   7896 7908   8072 8112   8076 8116   8080 8120   8084 8124   8088 8128   8092 8104   8096 8108   8172 8212   8176 8216   8180 8220   8184 8224   8188 8228   8192 8204   8196 8208   8272 8312   8276 8316   8280 8320   8284 8324   8288 8328   8292 8304   8296 8308   8472 8512   8476 8516   8480 8520   8484 8524   8488 8528   8492 8504   8496 8508   8572 8612   8576 8616   8580 8620   8584 8624   8588 8628   8592 8604   8596 8608   8672 8712   8676 8716   8680 8720   8684 8724   8688 8728   8692 8704   8696 8708   8872 8912   8876 8916   8880 8920   8884 8924   8888 8928   8892 8904   8896 8908   8972 9012   8976 9016   8980 9020   8984 9024   8988 9028   8992 9004   8996 9008   9072 9112   9076 9116   9080 9120   9084 9124   9088 9128   9092 9104   9096 9108   9272 9312   9276 9316   9280 9320   9284 9324   9288 9328   9292 9304   9296 9308   9372 9412   9376 9416   9380 9420   9384 9424   9388 9428   9392 9404   9396 9408   9472 9512   9476 9516   9480 9520   9484 9524   9488 9528   9492 9504   9496 9508   9672 9712   9676 9716   9680 9720   9684 9724   9688 9728   9692 9704   9696 9708   9772 9812   9776 9816   9780 9820   9784 9824   9788 9828   9792 9804   9796 9808   9872 9912   9876 9916   9880 9920   9884 9924   9888 9928   9892 9904   9896 9908   

06 度度熊的01世界

&emps;题意是给一个01图当1包围着只有一个由0组成的连通图的时候就是0,当不包围由0组成的连通图就是1,其他情况就为-1。
&emps;注意这道题所有1必须要连通才有0或1。那就进行标记,先把1组成的连通图外面的0标记掉,那么剩下遇到1所连接的0就一定被包含在1联通块里面,每遇到一次未染色标记的0就对这个0所组成的块进行染色标记,统计会遇到几个未染色标记的0。为0是答案就是1,为1时答案就是0,其他为-1。

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int h, w;int coo;char mapp[202][202];int mappp[250][250];int vis[202][202];int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};void dfs(int x, int y){    if(mappp[x][y] != 0)        return;    if(vis[x][y] == 1)        return;    vis[x][y] = 1;    for(int i = 0;i < 4;i++)    {        if(x + dir[i][0] >= 0&&x + dir[i][0] <= h + 1&&y + dir[i][1] >= 0&&dir[i][1] + y <= w + 1)        {            dfs(x + dir[i][0], y + dir[i][1]);        }    }    return;}void DFS(int x, int y){    if(mappp[x][y] == 0)    {        coo++;        dfs(x, y);        return;    }    vis[x][y] = 1;    for(int i = 0;i < 4;i++)    {        if(x + dir[i][0] >= 0&&x + dir[i][0] <= h + 1&&y + dir[i][1] >= 0&&dir[i][1] + y <= w + 1)        {            if(vis[x + dir[i][0]][y + dir[i][1]] == 0)            {                DFS(x + dir[i][0], y + dir[i][1]);            }        }    }    return;}int main(){    while(scanf("%d%d", &h, &w) != EOF)    {        coo = 0;        int flag = 0;        memset(vis, 0, sizeof(vis));        memset(mappp, 0, sizeof(mappp));        for(int i = 0;i < h;i++)            scanf("%s", mapp[i]);        for(int i = 1;i <= h;i++)            for(int j = 1;j <= w;j++)                mappp[i][j] = mapp[i - 1][j - 1] - '0';        dfs(0, 0);        for(int i = 1;i <= h;i++)        {            for(int j = 1;j <= w;j++)            {                if(mappp[i][j] == 1&&vis[i][j] == 0)                {                    flag++;                    vis[i][j] = 1;                    DFS(i, j);                }            }        }        if(coo == 0&&flag == 1)            printf("1\n");        else if(coo == 1&&flag == 1)            printf("0\n");        else            printf("-1\n");    }    return 0;}