#F time display
Time limit: 1.0s memory limit: 512.0MB total score: 15} points
Problem description
Xiaolan wants to cooperate with her friends to develop a time display website. On the server, the friend has obtained the current time, which is expressed as an integer. The value is the number of milliseconds from 00:00:00 on January 1, 1970 to the current time.
now, Xiaolan wants to display this time on the client. Xiaolan doesn't need to display the year, month and day. It only needs to display the hour, minute and second, and the millisecond doesn't need to be displayed. It can be directly rounded off.
given a time expressed as an integer, please output the hour, minute and second corresponding to this time.
Input format
the input line contains an integer representing the time.
Output format
output the current time represented by hour, minute and second. The format is as follows: H H: m, M: s, where h represents hour, the value is 0 to 23, m, M represents minute, the value is 0 to 59, and s represents second, the value is 0 to 59. When the hour, minute and second are less than two digits, the leading 0 shall be supplemented.
import java.util.Scanner; public class questionF { // #F time display public static void main(String[] args) { // Convert hours, minutes and seconds according to milliseconds Scanner sc=new Scanner(System.in); long t = sc.nextLong(); System.out.printf("%02d:%02d:%02d",t/3600000%24,t/60000%60,t/1000%60); } }
#G minimum weight
Time limit: 1.0s memory limit: 512.0MB total score of this question: 20 points
Problem description
you have a balance. Now you need to design a set of weights, so that you can use these weights to weigh any positive integer weight less than or equal to N °.
how many weights should this set of weights contain at least?
note that the weight can be placed on both sides of the balance.
Input format
the input contains a positive integer N.
Output format
output an integer representing the answer.
import java.util.Scanner; public class questionG { // #G minimum weight public static void main(String[] args) { // Find the solution according to the law Scanner sc=new Scanner(System.in); long x=sc.nextLong(); long sum=1,cur=1; while(sum<x){ sum+=Math.pow(3, cur); cur++; } System.out.println(cur); } }
#H Yang Hui triangle
Time limit: 5.0s memory limit: 512.0MB total score of this question: 20 points
the following figure is the famous Yang Hui triangle:
if we arrange all the numbers in one column from top to bottom and from left to right, we can get the following sequence:
1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, ...
given a positive integer n, what number is the first occurrence of N in the output sequence?
Input format
enter an integer N.
Output format
output an integer representing the answer.
import java.util.Scanner; public class questionH { // #H Yang Hui triangle static int N; public static void main(String[] args) { // Find out the solution according to the law of each layer Scanner sc=new Scanner(System.in); N = new Scanner(System.in).nextInt(); if (N == 1) System.out.println(1); else { long ans = (N + 1L) * N / 2 + 2; for (int m = 2; m < 16; m++) { int start = m * 2, end = N; while (start <= end) { int mid = start + end >> 1; if (C(mid, m) == N) { ans = min(ans, (mid + 1L) * mid / 2 + m + 1); break; } if (C(mid, m) > N) end = mid - 1; else start = mid + 1; } } System.out.println(ans); } } public static long min(long a, long b) { return a < b ? a : b; } public static long C(int n, int m) { long num = 1; for (int nm = 1; nm <= m; n--, nm++) if ((num = num * n / nm) > N) return num; return num; } }