4个小时,下来感觉,迷迷糊糊的(感觉写的题和没写一样,要么暴力,要么写写if els,感觉没有什么体验感。前两个填空题都是签到,第二个填空写的暴力,感觉跑了5分钟左右,其实是可以前缀和优化的,第三个题就不会那个输入了,后面迷糊的有点忘了,用的学校机房的电脑(悲,用着不太习惯,到9点整才解除电脑控屏,到那时我才把那个idea,加载数据qwq..还要调式那个idea,
第一题:求20 24的倍数的第202420242024项是什么?
数学:其实就是除2乘24,
private static void solve()throws IOException { long n=24,m=101210121012L; pw.println(n*m); }
第二题:
题意不好读,其实题意大概是假设一个数字n其数位有k,用前k位累加就是当前的一位的数值,一开始的k位,是n这个数字按位拆开,赛时写的代码依托答辩,
import java.util.*;import java.io.*;public class Main { static int N=(int)1e6+7; static int[] a; static int n,m,q,k; static List<Integer>[] g=new ArrayList[N]; static boolean f(int n){ int cnt=0,t=n; while(t>0){ cnt++; t/=10; } int[] nums=new int[N]; t=0; int m=n; while(m>0){ t=t*10+m%10; m/=10; } for(int i=0;i<cnt;i++){ nums[i]=t%10; t/=10; } for(int i=cnt;;i++){ for(int j=i-1,c=cnt;c>0;c--,j--){ nums[i]+=nums[j]; } if(nums[i]==n) { for(int j=0;j<=i;j++){ pw.print(nums[j]+" "); } pw.println(); return true; } if(nums[i]>n){ return false; } } } private static void solve()throws IOException { int mx=(int)1e7; for(int i=mx;i>=0;i--){ if(f(i)){ pw.println(i); break; } } /* 7 9 1 3 8 3 7 38 69 129 257 511 1014 2025 4043 8048 16027 31925 63593 126675 252336 502647 1001251 1994454 3972881 79138377913837 */ } public static void main(String[] args)throws IOException { int T=1; for(int i=1;i<=T;i++){ solve(); } pw.flush(); pw.close(); } static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer st=new StreamTokenizer(br); static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); static int nextInt()throws IOException{ st.nextToken(); return (int)st.nval; } static int nextLong()throws IOException{ st.nextToken(); return (int)st.nval; }}
第三题:
按题意模拟即可,不会输入的哭死,不太清楚下面的代码,输入有没有问题
//package A;import java.util.*;import java.io.*;public class Main { static int N=(int)2e5+7,INF=0x3f3f3f3f; static int[] a; static int n,m,q,k; static List<Integer>[] g=new ArrayList[N]; private static void solve()throws IOException { n=sc.nextInt();// pw.println(n); pw.flush(); a=new int[n];// for(int i=0;i<11;i++) while(sc.hasNext()) { String s=sc.next(); if(s.equals("add")) { int k=sc.nextInt(); a[0]++; } else if(s.equals("query")){ int ans=a[0]; for(int j=0;j<n;j++) ans=Math.min(ans,a[j]); System.out.println(ans); } else if(s.equals("sync")) { int k=sc.nextInt(); if(a[k]<a[0]) a[k]++; } } } /*3add 1add 2queryadd 1sync 1sync 1sync 2querysync 1querysync 2sync 2sync 1query */ public static void main(String[] args)throws IOException { int T=1; for(int i=1;i<=T;i++){ solve(); }// pw.flush();// pw.close(); } static Scanner sc=new Scanner(System.in); static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer st=new StreamTokenizer(br); static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); static int nextInt()throws IOException{ st.nextToken(); return (int)st.nval; } static int nextLong()throws IOException{ st.nextToken(); return (int)st.nval; }}
第四题:
发现暴力不太会写,写的单次查询o1,但是写到后面感觉有太多情况了,这if else太吓人了,,,
直接草草收场,交了
//package A;import java.util.*;import java.io.*;public class Main { static int N=(int)2e5+7,INF=0x3f3f3f3f; static int[] a; static int n,m,q,k; static List<Integer>[] g=new ArrayList[N]; private static void solve()throws IOException { int n=nextInt(); for(int i=0;i<n;i++){ int c2=nextInt(),c3=nextInt(),c4=nextInt(); int b4=nextInt(),b6=nextInt(); int ans=0,k3=c3/2; //三人凑6人桌 if(b6>=k3){ b6-=k3; c3-=k3*2; ans+=k3*6; } else{ ans+=b6*6; c3-=2*b6; b6=0; } int mi=Math.min(c2,c4); if(b6>=mi){ //在考虑2 4人凑6人桌 b6-=mi; c2-=mi; c4-=mi; ans+=6*mi; } else{ c2-=b6; c4-=b6; ans+=b6*6; b6=0; } if(b4>=c4){ //4人,安排4人桌子 ans+=c4*4; b4-=c4; c4=0; } else{ ans+=b4*4; c4-=b4; b4=0; } int k2=c2/2; if(b4>=k2){ //二分凑 4卓 b4-=k2; ans+=k2*4; c2-=2*k2; } else{ ans+=b4*4; c2-=2*b4; b4=0; } if(b4>=c3){ ans+=3*c3; b4-=c3; c3=0; } else{ ans+=b4*3; c3-=b4; b4=0; } int k=b4*2+b6*3; ans+=Math.min(k,c2); pw.println(ans); } /* 2 3 0 1 0 1 0 2 2 1 1 6 10 */ } public static void main(String[] args)throws IOException { int T=1; for(int i=1;i<=T;i++){ solve(); } pw.flush(); pw.close(); } static Scanner sc=new Scanner(System.in); static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer st=new StreamTokenizer(br); static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); static int nextInt()throws IOException{ st.nextToken(); return (int)st.nval; } static int nextLong()throws IOException{ st.nextToken(); return (int)st.nval; }}
第五题:
直接看不懂中文了,瞎写的
第六题:
点的数量是1000,边的数量最多是5000,询问次数是5e4,对每一个询问,bfs求边数小于lim能到达的所有结点,时间复杂度是q(n+m)=5e4*6e3=3e8,好像差不多可以过,不可以过那么直接就是寄了
,最后用每一次询问可以到达的结点累加起来,再除一个n就是答案了
//package A;import java.util.*;import java.io.*;public class Main { static int N=(int)1e3+7; static int[] a,d=new int[N],q=new int[N]; static int n,m,q1,k; static List<Integer>[] g=new ArrayList[N]; static boolean[] vis=new boolean[N]; static int bfs(int start,int limit){ for(int i=1;i<=n;i++) d[i]=-1; int tt=-1,hh=0; q[++tt]=start; d[start]=0; while(tt>=hh){ int x=q[hh++];// pw.print(x+" "); for(int y:g[x]){ if(d[y]==-1&&d[x]+1<=limit){ q[++tt]=y; d[y]=d[x]+1; } } }// pw.println(); return tt+1; } private static void solve()throws IOException { for(int i=0;i<N;i++) g[i]=new ArrayList<>(); n=nextInt(); m=nextInt(); q1=nextInt(); for(int i=0;i<m;i++){ int x=nextInt(),y=nextInt(); g[x].add(y); g[y].add(x); } double ans=0; for(int i=0;i<q1;i++){ int st=nextInt(),lim=nextInt(); ans+=bfs(st,lim); } pw.printf("%.2f",ans/n); } /* 3 2 3 1 2 2 3 2 1 2 0 1 1 */ public static void main(String[] args)throws IOException { int T=1; for(int i=1;i<=T;i++){ solve(); } pw.flush(); pw.close(); } static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer st=new StreamTokenizer(br); static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); static int nextInt()throws IOException{ st.nextToken(); return (int)st.nval; } static int nextLong()throws IOException{ st.nextToken(); return (int)st.nval; }}
第七题:
写的暴力+剪枝,对每一个字母枚举是否可以旋转,可能有两种或者4种情况,然后再对每一次旋转情况,做一边dfs,判断是否可以包含4个字母,感觉写dfs的话就是码农题了,不知道这个题可以不可以状态压缩dp,QAQ
//package A;import java.util.*;import java.io.*;public class Main { static int N=57; static int[][] a=new int[N][N],b=new int[N][N]; static int n,m,q1,k; static boolean[] vis=new boolean[N]; static int[][] d1x=new int[4][]; static int[][] d2x=new int[4][]; static int[][] d3x=new int[4][]; static int[][] d4x=new int[4][]; static int[][] d1y=new int[4][]; static int[][] d2y=new int[4][]; static int[][] d3y=new int[4][]; static int[][] d4y=new int[4][]; static int[][] dx=new int[4][],dy=new int[4][]; static boolean ok; static void dfs(int x,int y,int dep){ if(dep==4||ok){ ok=true; return; } if(y==n){ x++;y=0; } if(x==n) return; dfs(x,y+1,dep); if(a[x][y]==1){ boolean flag=true; int k=4; if(dep==1||dep==3) k=2; for(int i=0;i<k;i++){ int bx=dx[dep][i]+x,by=dy[dep][i]+y; if(bx<0||by<0||bx>=n||by>=n||a[bx][by]!=1){ flag=false; break; } } if(!flag) return; for(int i=0;i<k;i++){ //改 int bx=dx[dep][i]+x,by=dy[dep][i]+y; a[bx][by]=2; } dfs(x,y+1,dep+1); for(int i=0;i<k;i++){ //复原 int bx=dx[dep][i]+x,by=dy[dep][i]+y; a[bx][by]=b[bx][by]; } } } private static void solve()throws IOException { n=nextInt(); for(int i=0;i<n;i++) for(int j=0;j<n;j++) { a[i][j]=nextInt(); b[i][j]=a[i][j]; } for(int i1=0;i1<3;i1++) for(int i2=0;i2<2;i2++) for(int i3=0;i3<2;i3++) for(int i4=0;i4<3;i4++){ dx[0]=d1x[i1]; dx[1]=d2x[i2]; dx[2]=d3x[i3]; dx[3]=d4x[i4]; dy[0]=d1y[i1]; dy[1]=d2y[i2]; dy[2]=d3y[i3]; dy[3]=d4y[i4]; for(int i=0;i<n;i++) for(int j=0;j<n;j++) a[i][j]=b[i][j]; ok=false; dfs(0,0,0); if(ok){ pw.println("Yes"); return; } } pw.println("No"); } /*251 1 1 1 11 0 1 1 01 0 0 0 11 0 1 0 11 1 1 1 151 0 0 1 11 1 1 1 11 1 1 1 01 1 1 0 10 1 1 1 1 */ public static void main(String[] args)throws IOException { //1 d1x[0]=new int[]{0,1,2,2}; d1y[0]=new int[]{0,0,0,1}; d1x[1]=new int[]{0,0,0,1}; d1y[1]=new int[]{0,1,2,0}; d1x[2]=new int[]{0,0,1,2}; d1y[2]=new int[]{0,1,1,1}; d1x[3]=new int[]{0,1,1,1}; d1y[3]=new int[]{0,0,-1,-2}; //2 d2x[0]=new int[]{0,1,2,3}; d2y[0]=new int[]{0,0,0,0}; d2x[1]=new int[]{0,0,0,0}; d2y[1]=new int[]{0,1,2,3}; //3 d3x[0]=new int[]{0,0,0,1}; d3y[0]=new int[]{0,1,2,1}; d3x[1]=new int[]{0,1,2,1}; d3y[1]=new int[]{0,0,0,-1}; d3x[2]=new int[]{0,1,1,1}; d3y[2]=new int[]{0,0,-1,1}; d3x[3]=new int[]{0,1,2,1}; d3y[3]=new int[]{0,0,0,1}; //4 d4x[0]=new int[]{0,0,1,1}; d4y[0]=new int[]{0,1,0,-1}; d4x[1]=new int[]{0,1,1,2}; d4y[1]=new int[]{0,0,1,2}; int T=nextInt(); for(int i=1;i<=T;i++){ solve(); } pw.flush(); pw.close(); } static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer st=new StreamTokenizer(br); static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); static int nextInt()throws IOException{ st.nextToken(); return (int)st.nval; } static int nextLong()throws IOException{ st.nextToken(); return (int)st.nval; }}
第八题:
写的O(n^2)暴力o.O,,其实可以分颜色暴力的,但是写完上面那个码农提,脑子拓机了
package A;import java.util.*;import java.io.*;public class Main { static int N=(int)1e5+7,mod=(int)1e9; static int[] a=new int[N],b=new int[N],c=new int[N]; static int n,m,q1,k; static List<Integer>[] g=new ArrayList[N]; static void dfs(int x,int y){ } private static void solve()throws IOException { n=nextInt(); for(int i=0;i<n;i++){ a[i]=nextInt(); b[i]=nextInt(); c[i]=nextInt(); } long ans=0; for(int i=0;i<n;i++){ for(int j=0;j<i;j++){ if(c[i]==c[j]) continue; if(a[i]>b[j]&&b[i]<a[j]||(a[i]<b[j]&&b[i]>a[j])) ans++; } } pw.println(ans%mod); } /* 5 1 10 0 6 6 0 8 6 1 6 10 0 1 2 1 */ public static void main(String[] args)throws IOException { int T=1; for(int i=1;i<=T;i++){ solve(); } pw.flush(); pw.close(); } static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer st=new StreamTokenizer(br); static PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out)); static int nextInt()throws IOException{ st.nextToken(); return (int)st.nval; } static int nextLong()throws IOException{ st.nextToken(); return (int)st.nval; }}
总结一下:java还是不会那个不确定个数的输入,赛时一直再调,不太习惯写java,当然主要原因还是因为菜(菜是原罪,思路跟不上手速,就写下这么多吧,等下要去看奥德曼打怪兽了(哥斯拉2,QWQ
预祝大家都是省一啊o.O,o.O,