10月5日CSP-J模拟赛改错

· · 个人记录

10月5日CSP-J模拟赛改错

::::warning[No.1] 因数个数大于1e3+5,应写成1e4+5,故痛失10分qwq

Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 1e3+5;
long long n;
long long t[N], cnt = 0;
int main() {
    freopen("square.in", "r", stdin);
    freopen("square.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (long long i = 1; i <= n / i; i++) {
        if (n % i == 0) {
            t[++cnt] = i;
            if (n / i != i)t[++cnt] = n / i;
        }
    }
    sort(t + 1, t + 1 + cnt);
    for (long long i = cnt; i >= 1; i--) {
        if ((long long)(sqrt(t[i])) * (long long)(sqrt(t[i])) == t[i]) {
            cout << t[i] << '\n';
            return 0;
        }
    }
    return 0;
}

AC Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 1e4+5;
long long n;
long long t[N], cnt = 0;
int main() {
    freopen("square.in", "r", stdin);
    freopen("square.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (long long i = 1; i <= n / i; i++) {
        if (n % i == 0) {
            t[++cnt] = i;
            if (n / i != i)t[++cnt] = n / i;
        }
    }
    sort(t + 1, t + 1 + cnt);
    for (long long i = cnt; i >= 1; i--) {
        if ((long long)(sqrt(t[i])) * (long long)(sqrt(t[i])) == t[i]) {
            cout << t[i] << '\n';
            return 0;
        }
    }
    return 0;
}

::::: ::::warning[No.2] 注意到,题目中的数据范围会使ans*i溢出,故ans=ans*i/mod;错误,*`ans = (ans%mod) (i%mod) % mod;`正确 ,故痛失10分qwq**

Code

#include<iostream>
using namespace std;
const long long mod = 1000000007;
long long n, m, ans = 1;
int main() {
    freopen("lineup.in", "r", stdin);
    freopen("lineup.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    long long l = n - m;
    for (long long i = l + 1; i <= n; i++) {
        ans=ans*i/mod;
    }
    cout << ans;
    return 0;
}

AC Code

#include<iostream>
using namespace std;
const long long mod = 1000000007;
long long n, m, ans = 1;
int main() {
    freopen("lineup.in", "r", stdin);
    freopen("lineup.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    long long l = n - m;
    for (long long i = l + 1; i <= n; i++) {
        ans = (ans%mod) * (i%mod) % mod;
    }
    cout << ans;
    return 0;
}
:::::
::::error[No.3]
**注意到PDF中写道`4、选手提交源文件必须不大于100KB。`,但我的程序是打表复制到代码中,总代码600KB左右,** **~~故痛失100分qwq~~**  
#### 可以记忆化,先输入后判断是否计算过,计算过就读取、输出、结束,未计算就计算一遍,存入数组。
### Code
~~~cpp

#include<iostream>
using namespace std;
long long t;
const int N = 1e5+5;
int db[N] = {0, 7, 14, 17, 21, 27, 28, 35, 37, 42, 47, 49, 56, 57, 63, 67, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 84, 87, 91, 97, 98, 105, 107, 112, 117, 119, 126, 127, 133, 137, 140, 147, 154, 157, 161, 167, 168, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 182, 187, 189, 196, 197, 203, 207, 210, 217, 224, 227, 231, 237, 238, 245, 247, 252, 257, 259, 266, 267, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 287, 294, 297, 301, 307, 308, 315, 317, 322, 327, 329, 336, 337, 343, 347, 350, 357, 364, 367, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 385, 387, 392, 397, 399, 406, 407, 413, 417, 420, 427, 434, 437, 441, 447, 448, 455, 457, 462, 467, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 483, 487, 490, 497, 504, 507, 511, 517, 518, 525, 527, 532, 537, 539, 546, 547, 553, 557, 560, 567, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 581, 587, 588, 595, 597, 602, 607, 609, 616, 617, 623, 627, 630, 637, 644, 647, 651, 657, 658, 665, 667, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 686, 687, 693, 697, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 805, 807, 812, 817, 819, 826, 827, 833, 837, 840, 847, 854, 857, 861, 867, 868, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 882, 887, 889, 896, 897, 903, 907, 910, 917, 924, 927, 931, 937, 938, 945, 947, 952, 957, 959, 966, 967, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 987, 994, 997, 1001, 1007, 1008, 1015, 1017, 1022, 1027, 1029, 1036, 1037, 1043, 1047, 1050, 1057, 1064, 1067, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1085, 1087, 1092, 1097, 1099, 1106, 1107, 1113, 1117, 1120, 1127, 1134, 1137, 1141, 1147, 1148, 1155, 1157, 1162, 1167, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, .............} //因洛谷大小限制未写完,共599KB
int main() {
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        int n;
        cin >> n;
        cout << db[n] << '\n';
    }
    return 0;
}

AC Code

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int t[1000005];
bool isin(int x) {
    while (x) {
        if (x % 10 == 7)return 1;
        x /= 10;
    }
    return 0;
}
bool ishs(int x) {
    if (x % 7 == 0)return 1;
    return 0;
}
long long kth(int x) {
    if (t[x])return t[x];
    int cnt = 0, tem = 7;
    while (cnt != x) {
        if (isin(tem) || ishs(tem)) {
            cnt++;
            t[cnt] = tem;
        }
        tem++;
    }
    return t[cnt];
}
int main() {
    freopen("beauty.in", "r", stdin);
    freopen("beauty.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long t, k;
    cin >> t;
    while (t--) {
        cin >> k;
        cout << kth(k) << '\n';
    }
    return 0;
}

::::: ::::warning[No.4] ——没开long long见什么?
——见祖宗!!!

本某因没注意数据范围构造的hs[i]*(hs[i]-1)可能超过int范围,故痛失20分qwq ,所以将int改为long long即可。

Code

#include<iostream>
using namespace std;
int n;
int hs[105];
long long ans = 0;
int main() {
    freopen("hundred.in", "r", stdin);
    freopen("hundred.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        x %= 100;
        hs[x]++;
    }
    for (int i = 0; i < 100; i++) {
        if (hs[i] > 1) {
            ans += (( hs[i] - 1) * hs[i] / 2);
        }
    }
    cout << ans;
    return 0;
}

AC Code

#include<iostream>
using namespace std;
int n;
long long hs[105];
long long ans = 0;
int main() {
    freopen("hundred.in", "r", stdin);
    freopen("hundred.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        long long x;
        cin >> x;
        x %= 100;
        hs[x]++;
    }
    for (int i = 0; i < 100; i++) {
        if (hs[i] > 1) {
            ans += (hs[i] - 1) * hs[i] / 2;
        }
    }
    cout << ans;
    return 0;
}

:::::

!!!下面一题很重要

::::error[No.5]

错因:完全不会做

故痛失100分qwq

思路:

首先,发现可枚举长宽长度可行,得出代码ans=((n+1)*n/2)*((n+1)*n/2),但这里统计了正方形,所以应减去正方形数量,可发现:

当边长为1时有1个边长为1的正方形,
当边长为2时有4个边长为1的正方形,
当边长为3时有9个边长为1的正方形,
当边长为4时有16个边长为1的正方形,
当边长为n时有n^2个边长为1的正方形,

故总方形数量=

\sum_{i=1}^{n} i^2

代码如下:(因原代码是骗分的,一分没得,过于弱智,故不在此展示)

AC Code

#include<iostream>
#include<cstdio>
using namespace std;
long long n, ans;
int main() {
    freopen("rec.in", "r", stdin);
    freopen("rec.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    ans = ((n + 1) * n / 2) * ((n + 1) * n / 2);
    for (long long i = 1; i <= n; i++) {
        ans -= i * i;
    }
    cout << ans;
    return 0;
}

::::: ::::warning[No.6] 打的表,得了45分,故痛失55分qwq ,正解如下(不做证明):

AC Code

#include<iostream>
using namespace std;
#define ll long long
int main() {
    freopen("divisor.in", "r", stdin);
    freopen("divisor.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int cnt[105] = {0};
    for (int i = 2; i <= n; i++) {
        int a = i;
        for (int j = 2; j * j <= a; j++) {
            while (a % j == 0) {
                cnt[j]++;
                a /= j;
            }
        }
        if (a > 1) cnt[a]++;
    }
    ll ans = 1;
    for (int i = 2; i <= n; i++) {
        if (cnt[i] > 0) {
            ans *= (cnt[i] + 1);
        }
    }
    cout << ans;
    return 0;
}

:::::

总结

若不错那么多小细节,就能拿 满分 445分,以后应注重细节qwq

完结撒花!