zoukankan      html  css  js  c++  java
  • [BNU弱校联萌]强力热身

    链接:http://acm.bnu.edu.cn/v3/contest_show.php?cid=6865#info

    2.5H写了三道题,后面撸C题KMP一直TLE T.T三题就三题吧……

    A.Easy Math

    灵感突现,想到“无理数与任何数的和都不可能为整数”,居然1A,真是勇气的试练。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <iomanip>
     6 #include <cmath>
     7 #include <map>
     8 #include <vector>
     9 #include <string>
    10 #include <queue>
    11 #include <set>
    12 #include <algorithm>
    13 
    14 using namespace std;
    15 
    16 int n;
    17 int tmp;
    18 
    19 int main() {
    20     while(~scanf("%d", &n)) {
    21         int flag = true;
    22         for(int i = 0; i < n; i++) {
    23             scanf("%d", &tmp);
    24             double sq = sqrt(tmp);
    25             if(int(sq) != sq) {
    26                 flag = false;
    27             }
    28         }
    29         if(flag) {
    30             printf("Yes
    ");
    31         }
    32         else {
    33             printf("No
    ");
    34         }
    35     }
    36 }
    A

    B.Carries

    计算两两和有多少个进位。卡在了mod取10^9的时候会爆int,无数次WA…

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <iomanip>
     6 #include <cmath>
     7 #include <map>
     8 #include <vector>
     9 #include <string>
    10 #include <queue>
    11 #include <set>
    12 #include <algorithm>
    13 
    14 using namespace std;
    15 
    16 typedef long long LL;
    17 const int maxn = 1000010;
    18 int n;
    19 int a[maxn];
    20 int h[maxn];
    21 
    22 int main() {
    23     // freopen("in", "r", stdin);
    24     while(~scanf("%d", &n)) {
    25         memset(h, 0, sizeof(h));
    26         for(int i = 0; i < n; i++) {
    27             scanf("%d", &a[i]);
    28         }
    29         LL ans = 0;
    30         for(LL mod = 10; mod <= 1000000000; mod*=10) {    //no more than 10^9
    31             for(int i = 0; i < n; i++) {
    32                 h[i] = a[i] % mod;
    33             }
    34             sort(h, h+n);
    35             int m = n - 1;
    36             for(int i = 0; i < n; i++) {
    37                 while(i < m && h[i] + h[m] >= mod) {
    38                     m--;
    39                 }
    40                 ans += min(n-i-1, n-m-1);
    41             }
    42         }
    43         printf("%lld
    ", ans);
    44     }
    45 }
    B

    E.Rectangle

    和某微软笔试一样,确定一边暴力枚举另一边。 

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <iomanip>
     6 #include <cmath>
     7 #include <map>
     8 #include <vector>
     9 #include <string>
    10 #include <queue>
    11 #include <set>
    12 #include <algorithm>
    13 
    14 using namespace std;
    15 
    16 typedef long long LL;
    17 LL n, m, k;
    18     
    19 int main() {
    20     // freopen("in", "r", stdin);
    21     while(~scanf("%lld %lld %lld", &n, &m, &k)) {
    22         LL ans = 0;
    23         k /= 2;
    24         LL a, b;
    25         for(LL i = 1; i <= n; i++) {
    26             if(k < i) {
    27                 break;
    28             }
    29             LL tmp = min(k-i, m);
    30             a = n - i + 1;
    31             b = (m + (m - tmp + 1)) * tmp / 2;
    32             ans += a * b;
    33         }
    34         printf("%lld
    ", ans);
    35     }
    36 }
    E

    补题ing……

  • 相关阅读:
    mysql基础知识
    django知识
    gitlab的CICD搭建记录
    nginx的基础知识
    JAVA基础知识总结——part1
    【Python】python基础练习题_1
    【Docker】——Linux下搭建docker环境
    day3
    python_day2
    python_day1
  • 原文地址:https://www.cnblogs.com/kirai/p/4851812.html
Copyright © 2011-2022 走看看