• Codeforces Round #617 (Div. 3)


    这场练练golang

    题目链接:https://codeforces.com/contest/1296


    A:

    白给

     1 package main
     2 
     3 import "fmt"
     4 
     5 const (
     6     maxn = 2010
     7 )
     8 
     9 var (
    10     a    [maxn]int
    11     n, t int
    12 )
    13 
    14 func main() {
    15     fmt.Scan(&t)
    16     for cnt := 1; cnt <= t; cnt++ {
    17         var odd, even int
    18         fmt.Scan(&n)
    19         for i := 1; i <= n; i++ {
    20             var x int
    21             fmt.Scan(&x)
    22             if x&1 != 0 {
    23                 odd++
    24             } else {
    25                 even++
    26             }
    27         }
    28         if odd == 0 {
    29             fmt.Println("NO")
    30         } else if even == 0 {
    31             if n&1 != 0 {
    32                 fmt.Println("YES")
    33             } else {
    34                 fmt.Println("NO")
    35             }
    36         } else {
    37             fmt.Println("YES")
    38         }
    39     }
    40 }
    View Code

    B:

    注意每次给钱时保留个位不要给就行

     1 package main
     2 
     3 import "fmt"
     4 
     5 var (
     6     t int
     7 )
     8 
     9 func main() {
    10     fmt.Scan(&t)
    11     for cnt := 1; cnt <= t; cnt++ {
    12         var s, ans, tmp int
    13         fmt.Scan(&s)
    14         tmp = s
    15         for {
    16             var refound, yu = tmp / 10, tmp % 10
    17             ans += refound * 10
    18             if tmp < 10 {
    19                 ans += tmp
    20                 break
    21             }
    22             tmp = refound + yu
    23         }
    24         fmt.Println(ans)
    25     }
    26 }
    View Code

    C:

    做偏移量(x,y)到字符串下标的映射即可

     1 package main
     2 
     3 import "fmt"
     4 
     5 const maxn int = 2e5 + 10
     6 
     7 type pair struct {
     8     fir, sec int
     9 }
    10 
    11 var t int
    12 
    13 func main() {
    14     fmt.Scan(&t)
    15     for ; t > 0; t-- {
    16         var n int
    17         var s string
    18         fmt.Scan(&n, &s)
    19         s = " " + s
    20         var ans, l, r, x, y = n + 1, 0, 0, 0, 0
    21         m := make(map[pair]int)
    22         m[pair{0, 0}] = 1
    23         for i := 1; i < len(s); i++ {
    24             switch s[i] {
    25             case 'L':
    26                 x--
    27             case 'R':
    28                 x++
    29             case 'U':
    30                 y++
    31             case 'D':
    32                 y--
    33             }
    34             v := m[pair{x, y}]
    35             if v != 0 {
    36                 if ans > (i - v + 1) {
    37                     ans = i - v + 1
    38                     l = v
    39                     r = i
    40                 }
    41             }
    42             m[pair{x, y}] = i + 1
    43         }
    44         if ans == (n + 1) {
    45             fmt.Println("-1")
    46         } else {
    47             fmt.Println(l, r)
    48         }
    49     }
    50 }
    View Code

    D:

    对每个数,模a+b之后计算余数要a攻击次数,再O(n)贪心即可

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define dou double
     6 #define pb emplace_back
     7 #define mp make_pair
     8 #define sot(a,b) sort(a+1,a+1+b)
     9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
    10 #define rep0(i,a,b) for(int i=a;i<b;++i)
    11 #define eps 1e-8
    12 #define int_inf 0x3f3f3f3f
    13 #define ll_inf 0x7f7f7f7f7f7f7f7f
    14 #define lson (curpos<<1)
    15 #define rson (curpos<<1|1)
    16 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 2e5 + 10;
    21 int n, a, b, k, ans, h[maxn];
    22 
    23 int main() {
    24     scanf("%d%d%d%d", &n, &a, &b, &k);
    25     for (int i = 0; i < n; i++) {
    26         scanf("%d", &h[i]);
    27         h[i] %= a + b;
    28         if (!h[i]) h[i] = a + b;
    29         h[i] = (h[i] - 1) / a;
    30     }
    31     sort(h, h + n);
    32     for (int i = 0; i < n && k >= h[i]; i++) {
    33         k -= h[i]; ans++;
    34     }
    35     printf("%d
    ", ans);
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    Unbutu之web环境部署——常用软件安装
    利用百度uaredirect.js判断手机终端并自动跳转
    原生Ajax附件上传简单实例
    shader glsl 函数图举例
    pixijs释放纹理的方法
    pixijs shader透明度设置方法
    pixijs 用canvas的方法
    threejs 解决模型缩小有黑边的解决方案
    threejs 透明模型遮挡后面模型解决方案
    javascript canvas 清除图片空白多余的方法
  • 原文地址:https://www.cnblogs.com/JHSeng/p/12262172.html
Copyright © 2020-2023  润新知