A 门牌制作
答案:624
public class test_A {
public static void main(String[] args) {
int sum1=0;
int i;
for(i=1;i<=2020;i++){
int x=i;
while (x>0){
if(x%10==2){
sum1++;
}
x=x/10;
}
}
System.out.println(sum1);
}
}
B既约分数
答案:2481215
public class test_B {
public static void main(String[] args) {
int m,z,sum=0;
for(m=1;m<2020;m++){
for(z=m+1;z<=2020;z++){
if(f(z,m)){
sum++;
}
}
}
System.out.println(sum*2+1);
}
public static boolean f(int z,int m){
int x=Math.min(z,m);
for(int i=2;i<=x;i++){
if(z%i==0&&m%i==0){
return false;
}
}
return true;
}
}
C蛇形填空
答案:761
public class test_C {
public static void main(String[] args) {
int i=2*20-1;
int sum=0;
for(int x=1;x<i;x++){
sum=sum+x;
}
System.out.println((sum+1+sum+i)/2);
}
}
D跑步锻炼
答案:8879
public class test_D {
public static void main(String[] args) {
f();
}
public static void f(){
int year,month,day,week = 6,sum = 0;
int[] a={0,31,28,31,30,31,30,31,31,30,31,30,31};
for(year = 2000;year<=2020;year++)
{
if((year%400 == 0) || (year%4 == 0 && year %100!=0))
{
a[2] = 29;
}
for(month = 1;month <= 12;month++)
{
for(day = 1;day<=a[month];day++)
{
if(day == 1 || week == 1){
sum+=2;
}
else
sum+=1;
week = (week+1)%7;
if(year == 2020 && month == 10 && day == 1)
{
System.out.println(sum);
return ;
}
}
}
a[2] = 28;
}
}
}
E七段码
答案:80
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class test_E{
static Map<Character, Character[]> maps;
static Character[] arr = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
public static void main(String[] args) {
maps=new HashMap<>();
Character[] a = {'b', 'f'};
Character[] b = {'a', 'c', 'g'};
Character[] c = {'b', 'g', 'd'};
Character[] d = {'c', 'e'};
Character[] e = {'f', 'd', 'g'};
Character[] f = {'a', 'g', 'e'};
Character[] g = {'b', 'c', 'e', 'f'};
maps.put('a', a);
maps.put('b', b);
maps.put('c', c);
maps.put('d', d);
maps.put('e', e);
maps.put('f', f);
maps.put('g', g);
Set<Set<Character>> sets = dfs(arr, arr.length - 1);
System.out.println(sets.size());
}
private static Set<Set<Character>> dfs(Character[] A, int cur) {
Set<Set<Character>> new_set = new HashSet<>();
if (cur == 0) {
for (int i = 0; i < arr.length; i++) {
Set<Character> clone = new HashSet<>();
clone.add(A[i]);
new_set.add(clone);
}
return new_set;
}
Set<Set<Character>> old_set = dfs(A, cur - 1);
for (Set<Character> set : old_set) {
new_set.add(set);
Set<Character> tll =new HashSet<>();
for (Character character : set) {
Character[] characters = maps.get(character);
for (Character character1 : characters) {
if (!set.contains(character1)){
tll.add(character1);
}
}
}
for (Character character : A) {
if (tll.contains(character)){
Set<Character> clone = (Set<Character>) ((HashSet<Character>) set).clone();
clone.add(character);
new_set.add(clone);
}
}
}
return new_set;
}
}
F成绩统计
运行结果:
import java.util.Scanner;
public class test_F {
public static void main(String[] args) {
int j=0,y=0;
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
int m=sc.nextInt();
if(m>=60){
j++;
if(m>=85){
y++;
}
}
}
int jg=j*1000/n;
if((jg%10)>=5){
j=jg/10+1;
}else {
j=jg/10;
}
int yx=y*1000/n;
if(yx%10>=5){
y=yx/10+1;
}else {
y=yx/10;
}
System.out.println(j+"%");
System.out.println(y+"%");
}
}
G回文日期
运行结果:
import java.util.Scanner;
public class test_G {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
String s = sr.nextLine();
get(s);
}
public static void get(String s){
int date = Integer.parseInt(s);
int next = 0;
int nextAB = 0;
int times = 0;
int firstNext = 0;
for (date++;date <=89991231; date++){
if (huiwen(date) && isDate(date)) {
next = date;
times++;
if (isABhuiwen(date)) {
nextAB = date;
break;
}
if (times == 1)
firstNext = date;
}
}
System.out.println(Integer.toString(firstNext));
System.out.println(Integer.toString(nextAB));
}
private static boolean isABhuiwen(int date) {
String s = Integer.toString(date);
if(s.charAt(0) == s.charAt(2) && s.charAt(1) == s.charAt(3))
return true;
return false;
}
private static boolean isDate(int date) {
int year = date/10000;
int month = (date/100) %100;
int day = date % 100;
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
if (day <= 31) return true;
}
else if (month == 2 || month == 4 || month == 6 || month == 9 || month == 11){
if ((year % 4 == 0 && year % 100 != 0) || year % 4 == 0){
if (day <= 29) {
return true;
} else {
if (day <= 28)
return true;
}
}
}
return false;
}
private static boolean huiwen(int date) {
String s = Integer.toString(date);
int i = 0;
int j = s.length()-1;
while (i <= j ){
if (s.charAt(i) != s.charAt(j))
return false;
i++;
j--;
}
return true;
}
}
H子串分值和
运行结果:
import java.util.Scanner;
public class test_H {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String s=scanner.nextLine();
int sum=0;
for(int i=0;i<s.length();i++){
for (int j=i+1;j<=s.length();j++){
String m=s.substring(i,j);
int[] sz=new int[27];
for(int x=0;x<=j-i-1;x++){
if(sz[(int)m.charAt(x)-96]==0){
sum++;
sz[(int)m.charAt(x)-96]++;
}
}
}
}
System.out.println(sum);
}
}
I平面切分
运行结果:
import java.util.Scanner;
public class test_I {
public static int[][] d=new int[1000][2];
public static int l;
public static void main(String[] args) {
int sum=0;
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int[][] x=new int[n][2];
for (int i=0;i<n;i++){
x[i][0]=scanner.nextInt();
x[i][1]=scanner.nextInt();
}
if(n>=1){
sum=2;
}
int num;
for(int j=1;j<n;j++){
num=0;
for(int m=j-1;m>=0;m--){
if(x[m][0]!=x[j][0]){
int q=(x[m][1]-x[j][1])/(x[m][0]-x[j][0]);
int t=x[m][0]*q+x[m][1];
if(f(q,t)){
num++;}
}
}
if(num==0){
sum=sum+2;
}else {
sum=sum+num+1;
}
}
System.out.println(sum);
}
public static boolean f(int x,int y){
for(int i=0;i<l;i++){
if(x==d[i][0]&&y==d[i][1]){
return false;
}
}
l++;
d[l][0]=x;
d[l][1]=y;
return true;
}
}
J字串排序
运行结果:
import java.util.Scanner;
public class test_J {
public static int N = 135, M = 10010;
public static int[][][] f=new int[N][30][N];
public static int[][] chcnt=new int[N][30];
public static int[] mlen=new int[N];
public static void main(String[] args) {
dp();
Scanner scanner=new Scanner(System.in);
int score = scanner.nextInt();
int beg = 0;
for (int i = 1; i < N; ++i)
if (mlen[i] >= score)
{
beg = i;
break;
}
int curr = 0;
int same = 1;
char last = 'z' + 1;
for (int i = beg; i > 0; --i)
{
int j = 0;
for (; j <= last - 'a'; ++j)
{
if (j == last - 'a') curr -= same;
if (curr + chcnt[i][j] >= score)
{
curr += i - 1;
break;
}
}
if (j == last - 'a') same++;
else
{
last = (char)(j+97);
same = 1;
}
System.out.print(last);
}
System.out.println();
}
public static void dp()
{
for (int i = 2; i < N; ++i)
{
int m = 0;
for (int j = 1; j <= 'z' - 'a'; ++j)
{
for (int k = 1; k < i; ++k)
{
if (k > 1) f[i][j][k] = f[i - 1][j][k - 1] + i - k;
else f[i][j][k] = chcnt[i - 1][j - 1] + i - 1;
chcnt[i][j] = Math.max(chcnt[i][j], f[i][j][k]);
}
m = Math.max(m, chcnt[i][j]);
}
mlen[i] = m;
}
}
}
|