求梯形面积
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());
}
}
}
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());
}
}
}
题意是问整张图的所有九宫格中,黑色块的个数分别从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;
}