AtCoder Beginner Contest 045(4/4)

Trapezoids

求梯形面积

AC代码:

import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solve Work = new Solve();
        int T = 1;
        // int T = Integer.parseInt(in.next());
        for (int i = 1; i <= T; i++) {
            Work.main(i, in, out);
        }
        out.close();
    }
    static class Solve {
        public void main(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), h = in.nextInt();
            out.println((a + b) * h / 2);
        }
    }
    //IO
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Card Game for Three (ABC Edit)

模拟

AC代码:

import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solve Work = new Solve();
        int T = 1;
        // int T = Integer.parseInt(in.next());
        for (int i = 1; i <= T; i++) {
            Work.main(i, in, out);
        }
        out.close();
    }
    static class Solve {
        public void main(int testNumber, InputReader in, PrintWriter out) {
            String s1 = in.next(), s2 = in.next(), s3 = in.next();
            int len1 = s1.length(), len2 = s2.length(), len3 = s3.length();
            int nx = 1;
            for (int i = 0, j = 0, k = 0;;) {
                if (i == len1 && nx == 1) {
                    out.println("A");
                    return;
                } else if (j == len2 && nx == 2) {
                    out.println("B");
                    return;
                } else if (k == len3 && nx == 3) {
                    out.println("C");
                    return;
                }
                if (nx == 1) {
                    if (s1.charAt(i) == 'a') {
                        nx = 1;
                    } else if (s1.charAt(i) == 'b') {
                        nx = 2;
                    } else {
                        nx = 3;
                    }
                    i++;
                } else if (nx == 2) {
                    if (s2.charAt(j) == 'a') {
                        nx = 1;
                    } else if (s2.charAt(j) == 'b') {
                        nx = 2;
                    } else {
                        nx = 3;
                    }
                    j++;
                } else {
                    if (s3.charAt(k) == 'a') {
                        nx = 1;
                    } else if (s3.charAt(k) == 'b') {
                        nx = 2;
                    } else {
                        nx = 3;
                    }
                    k++;
                }
            }
        }
    }
    //IO
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Many Formulas

dfs爆搜

AC代码:

import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solve Work = new Solve();
        int T = 1;
        // int T = Integer.parseInt(in.next());
        for (int i = 1; i <= T; i++) {
            Work.main(i, in, out);
        }
        out.close();
    }
    static class Solve {
        String s;
        int len = 0;
        long ans = 0;
        public void main(int testNumber, InputReader in, PrintWriter out) {
            s = in.next();
            len = s.length();
            s = '#' + s;
            dfs(1, 0);
            out.println(ans);
        }
        public void dfs(int x, long y) {
            if (x == len + 1) {
                ans += y;
                return;
            }
            long now = 0;
            for (int i = x; i <= len; i++) {
                now = now * 10 + (int)(s.charAt(i) - '0');
                dfs(i + 1, y + now);
            }
        }
    }
    //IO
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Snuke's Coloring

题意是问整张图的所有九宫格中,黑色块的个数分别从0到9各有多少个

统计黑色块个数为0的情况时,不好直接统计,采取全部的(w-2)*(h-2)个九宫格减去含有黑色块的九宫格个数,可以知道每一个黑块能够影响的是包括他为中心的周围9个九宫格,所以可以离散化每个黑色块影响的9个九宫格,如果离散化后结果相等,说明在这个九宫格内有多个黑色块产生了影响,影响的个数即为这个九宫格内黑色块的数量,并且注意,位于边角的方格不能作为九宫格的中心点

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    LL h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int>> a(n);
    vector<LL> z;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (a[i].first - j >= 1 && a[i].first - j <= h - 2 && a[i].second - k >= 1 && a[i].second - k <= w - 2) {
                    LL p = 998244353LL * (a[i].first - j) + a[i].second - k;
                    z.push_back(p);
                }
            }
        }
    }
    
    sort(z.begin(), z.end());
    vector<LL> ans(10);
    ans[0] = (h - 2) * (w - 2);
    LL sum = 0;
    int len = z.size();
    for (int i = 0, cnt = 1; i < len; i++) {
        if (z[i] == z[i + 1]) {
            cnt++;
        } else {
            ans[cnt]++;
            cnt = 1;
            sum++;
        }
    }
    cout << ans[0] - sum << '\n';;
    for (int i = 1; i < 10; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值