第十四届省赛 c++ B组填空题
import java.util.*;
public class Main {
static int[] a = {5,6,8,6,9,1,6,1,2,4,9,1,9,8,2,3,6,4,7,7,5,9,5,0,3,8,7,5,8,1,5,8,6,1,8,3,0,3,7,9,2,7,0,5,8,8,5,7,0,9,9,1,9,4,4,6,8,6,3,3,8,5,1,6,3,4,6,7,0,7,8,2,7,6,8,9,5,6,5,6,1,4,0,1,0,0,9,4,8,0,9,1,2,8,5,0,2,5,3,3};
static Set<String> dates = new HashSet<>();
static int[] daysInMonth = {0,31,28,31,30,31,30,31,31,30,31,30,31};
static boolean[] used = new boolean[a.length];
static boolean isValidDate(String dateStr) {
int year = Integer.parseInt(dateStr.substring(0, 4));
int month = Integer.parseInt(dateStr.substring(4, 6));
int day = Integer.parseInt(dateStr.substring(6, 8));
if (year != 2023 || month < 1 || month > 12 || day < 1 || day > daysInMonth[month]) {
return false;
}
return true;
}
static void generateDateSequences(int index, String currentSequence) {
if (currentSequence.length() == 8) {
if (isValidDate(currentSequence)) {
dates.add(currentSequence);
}
return;
}
// 剪枝:如果当前序列已经无法凑成一个合法日期,则不继续向后递归
if (currentSequence.length() >= 4) {
String yearPart = currentSequence.substring(0, 4);
int year = Integer.parseInt(yearPart);
if (year != 2023) {
return;
}
}
// 剪枝:如果当前月份已经大于12,则不继续向后递归
if (currentSequence.length() >= 6) {
String monthPart = currentSequence.substring(4, 6);
int month = Integer.parseInt(monthPart);
if (month > 12) {
return;
}
}
// 剪枝:如果当前日期大于当前月份的天数,则不继续向后递归
if (currentSequence.length() >= 8) {
String dayPart = currentSequence.substring(6, 8);
int day = Integer.parseInt(dayPart);
String monthPart = currentSequence.substring(4, 6);
int month = Integer.parseInt(monthPart);
if (day > daysInMonth[month]) {
return;
}
}
for (int i = index; i < a.length; i++) {
if (!used[i]) {
used[i] = true;
generateDateSequences(i + 1, currentSequence + a[i]);
used[i] = false;
}
}
}
public static void main(String[] args) {
generateDateSequences(0, "");
System.out.println(dates.size());
}
}
public class Main {
public static void main(String[] args) {
int n = 23333333;
for (int i = 0; i <= n; i++) {
double x = (-1.0) * i / n * log2(1.0 * i / n, 2) * i;
double y = (-1.0) * (n - i) / n * log2(1.0 * (n - i) / n, 2) * (n - i);
if (x + y >= 11625907.5798) {
System.out.println(i);
return;
}
}
}
//如何计算logx(y)=ln(y)/ln(x); Math.log(x) = In(x)
public static double log2(double x, double base) {
return Math.log(x) / Math.log(base);
}
}
第十四届省赛 c++ C组填空题
long res = 0;
for (int i = 1; i <= 20230408; i++) {
res += i;
}
System.out.println(res);
/*
从文档当中把每个数据复制进来
*/
int res = 0;
LocalTime startTime = LocalTime.of(12,00,15);
LocalTime endTime= LocalTime.of(17,16,07);
while(!startTime.isAfter(endTime)){
startTime = startTime.plusSeconds(1);
res++;
}
System.out.println(res);
第十四届省赛 java B组填空题
/*
这题不能用暴力解决,毕竟10的11次方了。
这题只要求观察出1!到39之和后面的末尾9位数没有变过即可解决.
如果有接触过这种类型题,可快速完成.
*/
public class Main{
public static void main(String[] args) {
long sum=0;
long t=1000000000;
long temp=1;
for(int i=1;i<=10000;i++){
temp=(temp*i)%t;
sum=(sum+temp)%t;
System.out.println(sum);
}
}
}
public class Main{
static boolean check(int x){
int k = x;
int sum = 0;
while(k > 0){
int t = k % 10;
sum += t;
k /= 10;
}
if(x % sum != 0){
return false;
}
return true;
}
static boolean check2(int x){
int k = x;
int sum = 0;
while(k > 0){
sum += k % 8;
k = k / 8;
}
if(x % sum != 0){
return false;
}
return true;
}
static boolean check3(int x){
int k = x;
int sum = 0;
while(k > 0){
sum += k % 16;
k = k / 16;
}
if(x % sum != 0){
return false;
}
return true;
}
static boolean check4(int x){
int k = x;
int sum = 0;
while(k > 0){
sum += k % 2;
k = k / 2;
}
if(x % sum != 0){
return false;
}
return true;
}
public static void main(String[] args) {
int res = 0;
for(int i = 1;;i++){
if(check(i) && check2(i) && check3(i) && check4(i)){
//System.out.print(i + " ");
res++;
}
if(res == 2023){
System.out.println(i);
return;
}
}
}
}
第十四届省赛 java C组填空题
public class Main {
public static void main(String[] args) {
dfs(1, 9, 16);
System.out.println(sum);
}
static int sum = 0;
static void dfs(int x, int a, int b) {
if (x == 8) {
if (a == 0 && b == 0) {
//如果七个人恰好分完则计数加一
sum++;
}
return;
}
for (int i = 0; i <= a; i++) {
for (int j = 0; j <= b; j++) {
if (i + j >= 2 && i + j <= 5) {
//只有满足2-5的条件才可以
dfs(x + 1, a - i, b - j);
}
}
}
}
}