签到1
import java.util.Scanner;
public class 签到1 {
static int t, n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
t = sc.nextInt();
int a1, a2, a3;
while (t-- > 0) {
n = sc.nextInt();
a1 = n / 2;
a2 = (n - a1) * 2 / 3 ;
a3 = n - a1 - a2 ;
//不足10人也要指定一个向导 所以加9
System.out.println((a1 + 9)/10 + (a2 + 9)/10 + (a3 + 9)/10);
}
}
}
签到2
考虑输出0的情况,当n大于小数位数时。
import java.util.Scanner;
public class 签到2 {
static int t, n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
t = sc.nextInt();
while (t-- > 0) {
char[] arr = sc.next().toCharArray();
n = sc.nextInt();
int tem = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == '.') {
tem = i;
break;
}
}
while (n-- > 0) {
tem++;
}
if (tem >= arr.length) {
System.out.println(0);
continue;
}
System.out.println(arr[tem]);
}
}
}
签到3
递推一下,当n为奇数时这种情况不存在。
public class 签到3 {
static int n;
static long[] rec = new long[35];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
rec[2] = 3;
rec[0] = 1;
for (int i = 4; i <= 30; i+= 2) {
rec[i] = rec[i - 2]*4 - rec[i - 4] ;
}
while (true) {
n = sc.nextInt();
if (n == -1) {
return;
}
System.out.println(rec[n]);
}
}
}
签到4
public class 签到4 {
static int n;
static long[] rec = new long[65];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
rec[1] = 1;
rec[2] = 3;
for (int i = 3; i <= 64; i++) {
int min = Integer.MAX_VALUE;
for (int j = 1; j < i; j++) { //因为多了一根柱子,所以枚举出最少的次数
if (rec[j]*2 + Math.pow(2,i - j) - 1 < min) {
min = (int) (rec[j]*2 + Math.pow(2,i - j) - 1);
}
}
rec[i] = min;
}
while (sc.hasNext()) {
int n = sc.nextInt();
System.out.println(rec[n]);
}
}
}
签到5
import java.util.Scanner;
public class 签到5 {
static int n;
static long[] rec = new long[33000];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
rec[0] = 1;
for (int i = 1; i <= 3; i++) {
for (int j = i; j <= 32768; j++) {
rec[j] = rec[j - i] + rec[j];
}
}
while (sc.hasNext()) {
int n = sc.nextInt();
System.out.println(rec[n]);
}
}
}
签到6
注意最后一个数字后面不要有空格
public class 签到6 {
static int n;
static int[][] rec = new int[35][35];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
init();
while (sc.hasNext()) {
n = sc.nextInt();
f();
}
}
static void f() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(rec[i][j]);
if (j != i) System.out.print(" ");
}
System.out.println();
}
System.out.println();
}
static void init() {
for (int i = 1; i <= 30; i++) {
rec[i][1] = 1;
}
for (int i = 2; i <= 30; i++) {
for (int j = 2; j <= i; j++) {
rec[i][j] = rec[i - 1][j] + rec[i - 1][j - 1];
}
}
}
}
签到7
求出gcd(a,b) = 1的就是新朋友,用欧拉函数求出就是。
public class 签到7 {
static int n;
static int[] phi = new int[32769];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
init();
n = sc.nextInt();
while (n-- > 0) {
int num = sc.nextInt();
System.out.println(phi[num]);
}
}
static void init() {
for (int i = 1; i <= 32768; i++) {
phi[i] = i;
}
for (int i = 2;i <= 32768; i++) {
if (phi[i] == i) {
for (int j = i; j <= 32768; j += i) {
phi[j] = phi[j] / i * (i - 1);
}
}
}
}
}
签到8
import java.util.Scanner;
public class 签到8 {
static int t, n, k, mod = 9973;
static int[][] matrix;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
t = sc.nextInt();
while (t-- > 0) {
n = sc.nextInt();
k = sc.nextInt();
matrix = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = sc.nextInt();
}
}
int ans = matrix_pow();
System.out.println(ans);
}
}
//矩阵乘法
static int[][] matrix_mul(int[][] a,int[][] b) {
int[][] tem = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
tem[i][j] = (tem[i][j] + a[i][k] * b[k][j] % mod) % mod;
}
}
}
return tem;
}
static int matrix_pow() {
int ans = 0;
int[][] tem = new int[n][n];
//设置为单位矩阵
for (int i = 0; i < n; i++) {
tem[i][i] = 1;
}
//矩阵二分幂
while(k != 0) {
if ((k & 1) == 1) {
tem = matrix_mul(tem, matrix);
}
matrix = matrix_mul(matrix, matrix);
k /= 2;
}
//求对角线的和
for (int i = 0; i < n; i++) {
ans = (ans + tem[i][i]) % mod;
}
return ans;
}
}
签到9
二分法求出最后一位,每次都要取余。
import java.util.Scanner;
public class 签到9 {
static int a, b;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
a = sc.nextInt();
b = sc.nextInt();
pow();
}
}
static void pow() {
long num = 1;
long tem = a;
while (b != 0) {
if ((b & 1) == 1) {
num = (num * tem) % 10;
}
tem = (tem * tem) % 10;
b /= 2;
}
System.out.println(num % 10);
}
}
签到10
用欧拉求出区间,每次加上前一个数的个数就可以了
import java.util.Scanner;
public class 签到10 {
static int[] phi = new int[1000001];
static long[] rec = new long[1000001];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = System.currentTimeMillis();
init();
while (true) {
int n = sc.nextInt();
if (n == 0) {
return;
}
System.out.println(rec[n]);
}
}
static void init() {
for (int i = 1; i <= 1000000; i++) {
phi[i] = i;
}
for (int i = 2; i <= 1000000; i++) {
if (phi[i] == i) {
for (int j = i; j <= 1000000; j += i) {
phi[j] = phi[j] / i * (i - 1);
}
}
}
rec[2] = 1;
for (int i = 3; i <= 1000000; i++) {
rec[i] = rec[i - 1] + phi[i];
}
}
}