题目链接 https://www.nowcoder.com/acm/contest/80#question
A:zzy的小号
对于输入的字符串,是大小写的i,和l,有四种可能。对与,大小写的o和0算三种、对于其他字母算两种,对于数字算一种,记得每次都要取模、不然会爆掉、
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Scanner;
public class A {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static String next() throws IOException {
in.nextToken();
return (String) in.sval;
}
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
long mod = 1000000007;
String str = input.next(); // 有 StreamTokenizer 输入有问题、 会报异常、
long ans = 1;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'i' || str.charAt(i) == 'I' || str.charAt(i) == 'l' || str.charAt(i) == 'L') {
ans *= 4;
ans = ans % mod;
} else if (str.charAt(i) == 'O' || str.charAt(i) == '0' || str.charAt(i) == 'o') {
ans *= 3;
ans = ans % mod;
} else if ((str.charAt(i) >= 'a' && str.charAt(i) <= 'z')
|| (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z')) {
ans *= 2;
ans = ans % mod;
}
}
out.println(ans);
out.flush();
input.close();
}
}
B:jxc军训
费马小定理,计算a^(p - 2),快速幂,我用枚举、找最小的k
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class B {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static String next() throws IOException {
in.nextToken();
return (String) in.sval;
}
public static void main(String[] args) throws IOException {
int n = nextInt();
int m = nextInt();
long mod = 998244353;
int g = gcd(n * n - m, n * n);
long fz = (n * n - m) / g;
long fm = (n * n) / g;
int k = 0;
while (true) {
k++;
long pp = mod * k + 1;
if(pp % fm == 0) {
out.println((pp / fm) * (fz % mod) % mod);
out.flush();
break;
}
}
out.flush();
}
public static int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
}
C:zzf的好矩阵
这个求是是矩阵,在注意条件就是,只要有一个不相同就是不相同、而且是对角线对称的,所以要乘以2、二有多少个呐,
(1,2,3,4,,,,p) -> p!
输出 2 * (P!)^ 2 (注意 取模~~~)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class C {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static String next() throws IOException {
in.nextToken();
return (String) in.sval;
}
public static void main(String[] args) throws IOException {
long mod = 998244353;
int p = nextInt();
long ans = 1;
if (p == 1) {
out.println(ans);
} else {
for (int i = 1; i <= p; i++) {
ans = (ans * i) % mod;
}
out.println(2 * ans * ans % mod);
}
out.flush();
}
}
D:applese的生日(applese是个高中生dalao,膜)
每次都对最大的切分,而且是平分的那种、
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
public class D {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static String next() throws IOException {
in.nextToken();
return (String) in.sval;
}
public static void main(String[] args) throws IOException {
in.nextToken();
double rate = (double) in.nval;
int n = nextInt();
Node node[] = new Node[n];
for (int i = 0; i < n; i++) {
node[i] = new Node(nextInt(), 1);
}
Arrays.sort(node);
int ans = 0;
double eps = 0.0000001;
for (ans = 0; ans <= 505; ans++) {
double min = node[0].x, max = node[0].y;
int mid = 0;
for(int i = 0; i < n; i++) {
if(node[i].x > max + eps) {
max = node[i].x;
mid = i;
}
if(node[i].x + eps < min) {
min = node[i].x;
}
}
if(min + eps >max * rate) {
break;
}
node[mid].x *= node[mid].y / (node[mid].y + 1.0); // 按再切一刀平分
node[mid].y++;
}
out.println(ans);
out.flush();
}
static class Node implements Comparable<Node> {
int x, y; // 蛋糕的质量、 切的刀数
public Node() {
}
Node(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Node other) {
return this.x - other.x; // 质量的排序、、
}
}
}
E:VVQ与线段
这个题目用优先队列的做法,之前要排序,首先对输入的线段的左右端点进行排序,x优先比较原则,开两个优先队列(通过最小堆实现),一个装的是两个相交的情况、另一个装的是包含的情况、每次遍历线段时,都往两个里面扔,(线段树的做法,待续)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static String next() throws IOException {
in.nextToken();
return (String) in.sval;
}
public static void main(String[] args) throws IOException {
int n = nextInt();
Node node[] = new Node[n];
int l, r;
for (int i = 0; i < n; i++) {
l = nextInt();
r = nextInt();
node[i] = new Node(l, r);
}
Arrays.sort(node);
PriorityQueue<Point> q = new PriorityQueue<>(), qq = new PriorityQueue<>(); // 分别存储包含关系、和相交关系
int ans = 0, cnt = 0; // 存储最大的值 和线段的下标、、
for (Node z : node) {
while (!q.isEmpty() && node[q.peek().k].y < z.x) {
q.poll();
}
while (!qq.isEmpty() && node[qq.peek().k].y < z.x) {
qq.poll();
}
if (!q.isEmpty()) { // 包含关系
int x1 = z.y - z.x;
int x2 = q.peek().x;
ans = Math.max(ans, -x2 - x1); // 优先队列是最小堆实现的,所以、、
}
if (!qq.isEmpty()) { // 相交的情况、、
int x1 = z.y + z.x;
int x2 = qq.peek().x;
ans = Math.max(ans, x1 - x2);
}
q.add(new Point(z.x - z.y, cnt)); // 包含的状态 优先队列是通过最小堆实现的
qq.add(new Point(z.y + z.x, cnt)); // 相交的的状态、、
cnt++;
}
out.println(ans);
out.flush();
}
public static class MyComparator implements Comparator<Node> { // 自己定义的比较器、、、
@Override
public int compare(Node a, Node b) {
return a.x == b.x ? b.y - a.y : a.x - b.x;
}
}
static class Point implements Comparable<Point> {
int x, k; // 长度 和下标、
public Point() {
}
public Point(int x, int k) {
this.x = x;
this.k = k;
}
@Override
public int compareTo(Point o) {
return this.x == o.x ? o.k - this.k : this.x - o.x;
}
}
static class Node implements Comparable<Node> {
int x, y;
public Node() {
}
Node(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Node other) {
if (this.x == other.x) {
return this.y - other.y;
}
return this.x - other.x;
}
}
}