zoukankan      html  css  js  c++  java
  • 2019 The 19th Zhejiang University Programming Contest

    感想:

      今天三个人的状态比昨天计院校赛的状态要好很多,然而三个人都慢热体质导致签到题wa了很多发。最后虽然跟大家题数一样(6题),然而输在罚时。

      只能说,水题还是刷得少,看到签到都没灵感实在不应该。


    题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391

      A:简单贪心,按高度sort一下就好了,这里用优先队列处理

     1 #include <cstdio>
     2 #include <queue>
     3 #include <algorithm>
     4 #include <functional>
     5 
     6 using namespace std;
     7 
     8 int M[100005], F[100006];
     9 
    10 int main(void)
    11 {
    12     int T;
    13     while (scanf("%d", &T) != EOF)
    14     {
    15         while (T--)
    16         {
    17             int n, m;
    18             priority_queue <int, vector<int>, greater <int>> fu, fd, mu, md;
    19             scanf("%d %d", &n, &m);
    20             for (int i = 0; i < n; i++)
    21             {
    22                 scanf("%d", &M[i]);
    23             }
    24             for (int i = 0; i < m; i++)
    25             {
    26                 scanf("%d", &F[i]);
    27             }
    28             for (int i = 0; i < n; i++)
    29             {
    30                 int flag;
    31                 scanf("%d", &flag);
    32                 if (flag)
    33                 {
    34                     mu.push(M[i]);
    35                 }
    36                 else
    37                 {
    38                     md.push(M[i]);
    39                 }
    40             }
    41             for (int i = 0; i < m; i++)
    42             {
    43                 int flag;
    44                 scanf("%d", &flag);
    45                 if (flag)
    46                 {
    47                     fu.push(F[i]);
    48                 }
    49                 else
    50                 {
    51                     fd.push(F[i]);
    52                 }
    53             }
    54             int ans = 0;
    55             // fu <-> md
    56             while (!fu.empty() && !md.empty())
    57             {
    58                 if (fu.top() < md.top())
    59                 {
    60 //                  printf("pop: %d %d
    ", fu.top(), md.top());
    61                     fu.pop();
    62                     md.pop();
    63                     ans++;
    64                 }
    65                 else
    66                 {
    67 //                  printf("pop: %d
    ", md.top());
    68                     md.pop();
    69                 }
    70             }
    71             // fd <-> mu
    72             while (!mu.empty() && !fd.empty())
    73             {
    74                 if (mu.top() < fd.top())
    75                 {
    76 //                  printf("pop: %d %d
    ", mu.top(), fd.top());
    77                     mu.pop();
    78                     fd.pop();
    79                     ans++;
    80                 }
    81                 else
    82                 {
    83 //                  printf("pop: %d
    ", fd.top());
    84                     fd.pop();
    85                 }
    86             }
    87             printf("%d
    ", ans);
    88         }
    89     }
    90     return 0;
    91 }
    View Code

      B:找规律,显然是不停把n除二加起来,高精就用java

     1 import java.util.*;
     2 import java.lang.*;
     3 import java.math.BigInteger;
     4 
     5 public class Main {
     6 
     7     public static void main(String[] args) {
     8         Scanner cin=new Scanner(System.in);
     9         while (cin.hasNextInt())
    10         {
    11             int t=cin.nextInt();
    12             while (t-->0){
    13                 BigInteger ans=BigInteger.ZERO;
    14                 BigInteger x=cin.nextBigInteger();
    15                 while (!x.equals(BigInteger.ONE)){
    16                     x=x.divide(BigInteger.valueOf(2));
    17                     ans=ans.add(x);
    18                 }
    19                 System.out.println(ans);
    20             }
    21         }
    22     }
    23 }
    View Code

      C:模拟

      1 #include <cstdio>
      2 
      3 char t[2002][2002];
      4 bool vis[2002][2002];
      5 
      6 const int p3[] = {1, 3, 9, 27, 81, 243};
      7 
      8 const int movement[4][2] =
      9 {
     10     {1, 0}, // DOWN
     11     {0, 1},  // RIGHT
     12     {-1, 0}, // UP
     13     {0, -1} // LEFT
     14 };
     15 
     16 void init(int n, int m)
     17 {
     18     for (int i = 0; i < n; i++)
     19     {
     20         for (int j = 0; j < m; j++)
     21         {
     22             vis[i][j] = false;
     23         }
     24     }
     25 }
     26 
     27 int solve(void)
     28 {
     29     int ans = 0;
     30     int n, m;
     31     int a, b;
     32     long long int k;
     33     scanf("%d %d", &n, &m);
     34     scanf("%d %d %lld", &a, &b, &k);
     35     a--;
     36     b--;
     37     char cmd[300];
     38     scanf(" %s", cmd);
     39     init(n, m);
     40     for (int i = 0; i < n; i++)
     41     {
     42         scanf(" %s", t[i]);
     43         for (int j = 0; j < m; j++)
     44         {
     45             t[i][j] -= '0';
     46         }
     47     }
     48     while (k--)
     49     {
     50         int x = p3[4] * t[a][b]
     51                 + p3[3] * t[a - 1][b]
     52                 + p3[2] * t[a + 1][b]
     53                 + p3[1] * t[a][b - 1]
     54                 + p3[0] * t[a][b + 1];
     55         if (vis[a][b])
     56         {
     57             return ans;
     58         }
     59         vis[a][b] = true;
     60         if (cmd[x] == 'D')
     61         {
     62             int na = a + movement[0][0], nb = b + movement[0][1];
     63             if (t[na][nb] == 1) return ans;
     64             else a = na, b = nb;
     65         }
     66         else if (cmd[x] == 'R')
     67         {
     68             int na = a + movement[1][0], nb = b + movement[1][1];
     69             if (t[na][nb] == 1) return ans;
     70             else a = na, b = nb;
     71         }
     72         else if (cmd[x] == 'U')
     73         {
     74             int na = a + movement[2][0], nb = b + movement[2][1];
     75             if (t[na][nb] == 1) return ans;
     76             else a = na, b = nb;
     77         }
     78         else if (cmd[x] == 'L')
     79         {
     80             int na = a + movement[3][0], nb = b + movement[3][1];
     81             if (t[na][nb] == 1) return ans;
     82             else a = na, b = nb;
     83         }
     84         else if (cmd[x] == 'P')
     85         {
     86             if (t[a][b] == 2)
     87             {
     88                 t[a][b] = 0;
     89                 ans++;
     90                 init(n, m);
     91             }
     92         }
     93         else if (cmd[x] == 'I')
     94         {
     95             return ans;
     96         }
     97     }
     98     return ans;
     99 }
    100 
    101 int main(void)
    102 {
    103     int T;
    104     while (scanf("%d", &T) != EOF)
    105     {
    106         while (T--)
    107         {
    108             printf("%d
    ", solve());
    109         }
    110     }
    111     return 0;
    112 }
    View Code

      D:上一题的人工智能版,要你构造特定程序捡垃圾。方法是走回字形,比如我们选定顺时针方向走,那么当我们走到左边靠墙位置的时候,如果右手边有垃圾,那么我们往右走一格再继续往上走。如果走到地图中间位置(四周没垃圾)就往上走。如果机器人走了连续相同方向n次就让机器人“抖动”一下(属实人工智能调参)。然而cy他们队就是A了(神仙啊

      E:从右往左扫一次就好了,队友没开LL导致wa一发要批评

     1 #include <cstdio>
     2 
     3 long long int a[200], b[200];
     4 
     5 int main(void)
     6 {
     7     int T;
     8     while (scanf("%d", &T) != EOF)
     9     {
    10         while (T--)
    11         {
    12             int n;
    13             scanf("%d", &n);
    14             for (int i = 0; i < n; i++)
    15             {
    16                 scanf("%lld", &a[i]);
    17             }
    18             for (int i = 0; i < n; i++)
    19             {
    20                 scanf("%lld", &b[i]);
    21             }
    22             bool flag = true;
    23             for (int i = n - 1; i >= 0; i--)
    24             {
    25                 if (b[i] >= a[i])
    26                 {
    27                     if (i)
    28                     {
    29                         b[i - 1] += b[i] - a[i];
    30                     }
    31                 }
    32                 else
    33                 {
    34                     flag = false;
    35                     break;
    36                 }
    37             }
    38             printf(flag ? "Yes
    " : "No
    ");
    39         }
    40     }
    41     return 0;
    42 }
    View Code

      F:神仙题

      G:非常简单的贪心

     1 #include <cstdio>
     2 #include <queue>
     3 #include <algorithm>
     4 #include <functional>
     5 
     6 using namespace std;
     7 
     8 int M[100005], F[100006];
     9 
    10 int main(void)
    11 {
    12     int T;
    13     while (scanf("%d", &T) != EOF)
    14     {
    15         while (T--)
    16         {
    17             int n, k;
    18             scanf("%d %d", &n, &k);
    19             priority_queue <long long int> pos, neg;
    20             for (int i = 0; i < n; i++)
    21             {
    22                 int tmp;
    23                 scanf("%d", &tmp);
    24                 if (tmp > 0)
    25                 {
    26                     pos.push(tmp);
    27                 }
    28                 else
    29                 {
    30                     neg.push(-tmp);
    31                 }
    32             }
    33             long long int ans = 0, maxn = 0;
    34             while (!pos.empty())
    35             {
    36                 ans += 2 * pos.top();
    37                 maxn = max(pos.top(), maxn);
    38                 int cnt = k - 1;
    39                 pos.pop();
    40                 while (cnt-- && !pos.empty())
    41                 {
    42                     pos.pop();
    43                 }
    44             }
    45             while (!neg.empty())
    46             {
    47                 ans += 2 * neg.top();
    48                 maxn = max(neg.top(), maxn);
    49                 int cnt = k - 1;
    50                 neg.pop();
    51                 while (cnt-- && !neg.empty())
    52                 {
    53                     neg.pop();
    54                 }
    55             }
    56             printf("%lld
    ", ans - maxn);
    57         }
    58     }
    59     return 0;
    60 }
    View Code

      H:救公主,边双相关的题目(然而队友最后没撸出来)

       I:要求逆元的看不懂的题目

      J:签到(wa了7次,三个人都没睡醒。这里我马上想到了可以输出n×2和n×3,然而忘记特判n==1的情况……)

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 
     5 using namespace std;
     6 
     7 typedef long long ll;
     8 
     9 ll read()
    10 {
    11     ll x = 0; char c = getchar(); ll flag = 1;
    12     while (c < '0' || c > '9')
    13     {
    14         if (c == '-')
    15         {
    16             flag = -1;
    17         }
    18         c = getchar();
    19     }
    20     while (c >= '0' && c <= '9')x = x * 10ll + c - '0', c = getchar();
    21     return x;
    22 }
    23 
    24 int main()
    25 {
    26     ll T;
    27     while (scanf("%lld", &T) == 1)
    28     {
    29         while (T--)
    30         {
    31             ll x;
    32             x = read();
    33             if (x % 2 == 0)
    34             {
    35                 printf("4 %lld
    ", 4 + x);
    36             }
    37             else
    38             {
    39                 printf("15 %lld
    ", 15 + x);
    40             }
    41         }
    42     }
    43 
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    leetcode 13. Roman to Integer
    python 判断是否为有效域名
    leetcode 169. Majority Element
    leetcode 733. Flood Fill
    最大信息系数——检测变量之间非线性相关性
    leetcode 453. Minimum Moves to Equal Array Elements
    leetcode 492. Construct the Rectangle
    leetcode 598. Range Addition II
    leetcode 349. Intersection of Two Arrays
    leetcode 171. Excel Sheet Column Number
  • 原文地址:https://www.cnblogs.com/JHSeng/p/10706568.html
Copyright © 2011-2022 走看看