zoukankan      html  css  js  c++  java
  • 1019训练赛

    A水题:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 const int maxn = 25;
     7 
     8 int main() {
     9     int t, n, num;
    10     int m;
    11     scanf("%d",&t);
    12     while(t--) {
    13         int sum = 0;
    14         scanf("%d %d",&n, &m);
    15         while(n--) {
    16             scanf("%d",&num);
    17             sum += num;
    18         }
    19         if(sum > m) puts("Warning");
    20         else puts("Safe");
    21     }
    22     return 0;
    23 }
    View Code

    B:

    定义f[n] 为1 + 2  + ……+ n的和

    然后告诉你一个数问这个数最少由多少个f[i]组成  并输出i

    例如:

    20 = (1 + 2 + 3 + 4) + (1 + 2 + 3 + 4)

    19 = (1 + 2 + 3) + (1 + 2 + 3 + 4) + (1 + 2)

    6 = (1 + 2 + 3)

    9 = (1 + 2) + (1 + 2 + 3)

    分析:暴力枚举   通过打标可以发现 最多有3层

    代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 const int maxn = 15720;
     7 int a[maxn + 10];
     8 
     9 void init() {
    10     a[1] = 1;
    11     for(int i = 2; i < maxn; i++) {
    12         a[i] = a[i - 1] + i;
    13     }
    14 }
    15 
    16 int er(int num) {
    17     int low = 1; int high = maxn - 1;
    18     while(low <= high) {
    19         int mid = (low + high) >> 1;
    20         if(a[mid] > num) {
    21             high = mid - 1;
    22         } else {
    23             low = mid + 1;
    24         }
    25     }
    26     return high;
    27 }
    28 
    29 bool dfs(int de, int n, int ceng) {
    30     int num = er(n);
    31     if(a[num] == n) {
    32         printf("%d", num);
    33         return true;
    34     }
    35     if(de > ceng || n <= 0) return false;
    36     for(int k = 0; k < maxn; k++) {
    37         if(num > k && dfs(de + 1, n - a[num - k], ceng)) {
    38             printf(" %d", num - k);
    39             return true;
    40         }
    41     }
    42     return false;
    43 }
    44 
    45 int main() {
    46     init();
    47     int t; int n;
    48     scanf("%d",&t);
    49     while(t--) {
    50         scanf("%d",&n);
    51         for(int i = 1; i <= 10; i++) {
    52             if(dfs(1, n, i)) {
    53                 puts("");
    54                 break;
    55             }
    56         }
    57     }
    58     return 0;
    59 }
    View Code

    D:模拟水题

    代码:

     1 #include <algorithm>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <ctime>
     5 #include <iostream>
     6 
     7 #define mp make_pair
     8 #define pb push_back
     9 using namespace std;
    10 
    11 const int N = 10020;
    12 struct A {
    13     int x;
    14     int id;
    15     string date;
    16     int score;
    17     bool operator<(const A &t) const {
    18         if (score != t.score)
    19             return score > t.score;
    20         if (date != t.date)
    21             return date < t.date;
    22         return id < t.id;
    23     }
    24 } a[N];
    25 int n;
    26 int ans[N];
    27 char cmd[50];
    28 int main() {
    29     int cas, i;
    30     scanf("%d", &cas);
    31     while (cas--) {
    32         scanf("%d", &n);
    33         for (i = 1; i <= n; i++) {
    34             scanf("%d%s%d", &a[i].id, cmd, &a[i].score);
    35             a[i].date = cmd;
    36             a[i].x = i;
    37         }
    38         sort(a + 1, a + 1 + n);
    39         int cnt = 0;
    40         for (i = 1; i <= n; i++)
    41             if (a[i].score)
    42                 cnt++;
    43         int L6 = cnt * 3 / 100, L5 = cnt * 7 / 100, L4 = cnt * 20 / 100, L3 =
    44                 cnt * 30 / 100;
    45         for (i = 1; i <= n; i++) {
    46             if (!a[i].score)
    47                 ans[a[i].x] = 1;
    48             else if (i <= L6)
    49                 ans[a[i].x] = 6;
    50             else if (i <= L6 + L5)
    51                 ans[a[i].x] = 5;
    52             else if (i <= L6 + L5 + L4)
    53                 ans[a[i].x] = 4;
    54             else if (i <= L6 + L5 + L4 + L3)
    55                 ans[a[i].x] = 3;
    56             else
    57                 ans[a[i].x] = 2;
    58         }
    59         for (i = 1; i <= n; i++)
    60             printf("LV%d
    ", ans[i]);
    61     }
    62 }
    View Code

    I:模拟 水题

    代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 int main() {
     7     int t;
     8     string s3 = "Hello, world!";
     9     scanf("%d",&t);
    10     getchar();
    11     while(t--) {
    12         string s1, s2;
    13         getline(cin, s1);
    14         for(int i = 0; s1[i]; i++) {
    15             if(s1[i] == '!') {
    16                 s2 += s3;
    17             } else if(s1[i] == '_') {
    18                 s2 += s1;
    19             }
    20         }
    21         if(s1 == s2) {
    22             puts("Yes");
    23         } else {
    24             puts("No");
    25         }
    26     }
    27     return 0;
    28 }
    View Code

    h是个大数论  看题解看的脑袋都大了  回寝室想想

    周洲过了个大dp?这个回去也想想

    还有一个题跟高放说错了题意  抱歉了

    今天好没状态啊

    回寝了。

  • 相关阅读:
    (双指针 二分) leetcode 167. Two Sum II
    (双指针) leetcode 485. Max Consecutive Ones
    (双指针) leetcode 27. Remove Element
    (String) leetcode 67. Add Binary
    (数组) leetcode 66. Plus One
    (N叉树 BFS) leetcode429. N-ary Tree Level Order Traversal
    (N叉树 递归) leetcode 590. N-ary Tree Postorder Traversal
    (N叉树 递归) leetcode589. N-ary Tree Preorder Traversal
    (N叉树 DFS 递归 BFS) leetcode 559. Maximum Depth of N-ary Tree
    (BST 递归) leetcode98. Validate Binary Search Tree
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/4035616.html
Copyright © 2011-2022 走看看