1210. 连号区间数
蓝桥杯暴力过80%
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] res = new int[n];
int[] copy = new int[n];
for(int i=0;in;i++)
res[i] = sc.nextInt();
System.arraycopy(res, 0, copy, 0, n);
int sum = 0;
for(int i=0;in;i++) {
for(int j=i;jn;j++) {
System.arraycopy(copy, 0, res, 0, n);
Arrays.sort(res,i,j+1);//注意
boolean f = true;
for(int k=i+1;kj;k++) {
if(res[k]!=res[k-1]+1) {
f = false;
break;
}
}
if(f) {
sum++;
}
}
}
System.out.println(sum);
}
}
AC
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] res = new int[n];
for(int i=0;in;i++)
res[i] = sc.nextInt();
int s = 0;
for(int i=0;in;i++) {
int MAX = Integer.MIN_VALUE;
int MIN = Integer.MAX_VALUE;
for(int j=i;jn;j++) {
MAX = Math.max(MAX, res[j]);
MIN = Math.min(MIN, res[j]);
if((MAX-MIN) == (j-i)) s++;
}
}
System.out.println(s);
}
}
1236. 递增三元组
蓝桥杯暴力过62.5%
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n+1];
int[] b = new int[n+1];
int[] c = new int[n+1];
for(int i=1;in;i++)
a[i] = sc.nextInt();
for(int i=1;in;i++)
b[i] = sc.nextInt();
for(int i=1;in;i++)
c[i] = sc.nextInt();
int sum = 0;
for(int i=1;in;i++) {
for(int j=1;jn;j++) {
for(int k=1;kn;k++) {
if(a[i]b[j] && b[j]c[k])
sum++;
}
}
}
System.out.println(sum);
}
}
排序二分75%
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a 服务器托管网= new int[n+1];
int[] b = new int[n+1];
int[] c = new int[n+1];
for(int i=1;in;i++)
a[i] = sc.nextInt();
for(int i=1;in;i++)
b[i] = sc.nextInt();
for(int i=1;in;i++)
c[i] = sc.nextInt();
Arrays.sort(a);
Arrays.sort(b);
Arrays.sort(c);//排序
int sum = 0;
for(int i=1;in;i++) {
for(int j=1;jn;j++) {
int l = 1,r = n;
while(lr) {
int mid = (l+r)/2;
if(c[mid]>=b[j]) r = mid;
else l = mid+1;
}
for(int k=l;kn;k++) {
if(a[i]b[j] && b[j]c[k])
sum++;
}
}
}
System.out.println(sum);
}
}
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n+1];
int[] b = new int[n+1];
int[] c = new int[n+1];
for(int i=1;in;i++)
a[i] = sc.nextInt();
for(int i=1;in;i++)
b[i] = sc.nextInt();
for(int i=1;in;i++)
c[i] = sc.nextInt();
Arrays.sort(a);
Arrays.sort(b);
Arrays.sort(c);//排序
int sum = 0;
for(int i=1;in;i++) {
int sl = 1,sr = n;
while(slsr) {
int mid = (sl+sr)/2;
if(b[mid]>=a[i]) sr = mid;
else sl = mid+1;
}
for(int j=sl;jn;j++) {
int l = 1,r = n;
while(lr) {
int mid = (l+r)/2;
if(c[mid]>=b[j]) r = mid;
else l = mid+1;
}
for(int k=l;kn;k++) {
if(a[i]b[j] && b[j]c[k])
sum++;
}
}
}
System.out.println(sum);
}
}
加上快读75%
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
int[] a = new int[n+1];
int[] b = new int[n+1];
int[] c = new int[n+1];
String[] s1 = br.readLine().split(" ");
for(int i=1;in;i++)
a[i] = Intege服务器托管网r.parseInt(s1[i-1]);
String[] s2 = br.readLine().split(" ");
for(int i=1;in;i++)
b[i] = Integer.parseInt(s2[i-1]);
String[] s3 = br.readLine().split(" ");
for(int i=1;in;i++)
c[i] = Integer.parseInt(s3[i-1]);
Arrays.sort(a);
Arrays.sort(b);
Arrays.sort(c);//排序
int sum = 0;
for(int i=1;in;i++) {
int sl = 1,sr = n;
while(slsr) {
int mid = (sl+sr)/2;
if(b[mid]>=a[i]) sr = mid;
else sl = mid+1;
}
for(int j=sl;jn;j++) {
int l = 1,r = n;
while(lr) {
int mid = (l+r)/2;
if(c[mid]>=b[j]) r = mid;
else l = mid+1;
}
for(int k=l;kn;k++) {
if(a[i]b[j] && b[j]c[k])
sum++;
}
}
}
pw.println(sum);
pw.close();
}
}
1245. 特别数的和
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int sum = 0;
for(int i=1;in;i++) {
String ss = i+"";
char[] s = (i+"").toCharArray();
boolean f = false;
for(int j=0;js.length;j++) {
if(s[j] == '2'||s[j] == '0'||s[j] == '1'||s[j] == '9') {
// System.out.println(s);
f = true;
break;
}
}
if(f) {
sum+=Integer.parseInt(ss);
}
}
System.out.println(sum);
}
}
1204. 错误票据
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
MapInteger,Integer> map = new HashMap>();
sc.nextLine();
while(n-- != 0) {
String[] s = sc.nextLine().split(" ");
for(int i=0;is.length;i++)
map.put(Integer.parseInt(s[i]),map.getOrDefault(Integer.parseInt(s[i]), 0)+1);
}
int MAX = Integer.MIN_VALUE;
int MIN = Integer.MAX_VALUE;
int y = 0;
for(EntryInteger, Integer> entry:map.entrySet()) {
MAX = Math.max(MAX, entry.getKey());
MIN = Math.min(MIN, entry.getKey());
if(entry.getValue() == 2)
y = entry.getKey();
}
for(int i=MIN;iMAX;i++) {
if(!map.containsKey(i)) {
System.out.print(i+" "+y);
return ;
}
}
}
}
466. 回文日期
import java.util.Scanner;
public class Main{
static int[] days = new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
public static boolean check(int date) {
int year = date/10000;
int month = date%10000 /100;
int day = date%100;
//年
if(month == 2) {
boolean f = (year%100!=0 && year%4==0)||(year%400==0);//闰年
if(f) {
if(day>28+1) {//是闰年的话看看2月是不是超过了29天
return false;
}
}else {
if(day>28) {//不是闰年的话看看2月是不是超过了28天
return false;
}
}
}
//月
if(month == 0 || month > 12)//肯定是正数其次看看是不是1到12之间
return false;
//日
if(day == 0 || (month!=2 && day>days[month]))//正数其次是除了二月之外的月份天数不可以超过days数组对应的值
return false;
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int date1 = sc.nextInt();
int date2 = sc.nextInt();
int res = 0;
//遍历四位数
for(int i=1000;i10000;i++) {
int date = i,x = i;
for(int j=0;j4;j++) {
date = date*10+x%10;
x/=10;
}//构成回文数
if(date1 date && date date2 && check(date))//判断构成的回文数是不是正确日期
res++;
}
System.out.println(res);
}
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
单文件组件概念 Vue 的单文件组件 (即 *.vue 文件,英文 Single-File Component,简称 SFC) 是一种特殊的文件格式,使我们能够将一个 Vue 组件的模板、逻辑与样式封装在单个文件中。下面是一个单文件组件的示例: import{…