A:L1-1 I LOVE WIT
很简单的一个模拟题
只需要按照他的条件输出就好了,记得那两行空白是有空格的哦。
import java.math.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.*; public class Main { public static void main(String args[])throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); out.println( "I"); out.println(" "); out.println(" L"); out.println(" O"); out.println(" V"); out.println(" E"); out.println(" "); out.println(" W"); out.println(" I"); out.print( " T"); out.flush(); } }B:L1-2 单位换算
只需要将n乘以304.8即可,注意要分别是否小数点后是否为0,可以用 (n*304.8)==(int)(n*304.8)进行判断,然后用format取小数点后一位即可。
import java.math.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.*; public class Main { public static void main(String args[])throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); in.nextToken(); double n = in.nval; if((n*304.8)==(int)(n*304.8)) out.println((int)(n*304.8)); else{ out.println(String.format("%.1f",n*304.8)); } out.flush(); } }C:L1-3 Pokémon
这道题有一点陷阱,就是闪光的概率为指定v型的概率乘以0.01,要是普通的概率为指定v型概率乘以0.99,而不是1.
如果仔细看到这里的话就不会出错啦。
D:L1-4 颠倒阴阳
模拟题,先把n每一位遍历一遍,如果是0就换成1,相反。
然后再把s字符串补0补齐32位。
然后遍历&1==1的话就加到sum中。
记得开long
import java.math.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.*; public class Main { public static void main(String args[])throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); in.nextToken(); long n = (long)in.nval; String s=""; while(n>0) { if((n&1)==1) s = s+0; else{ s = s+1; } n>>=1; } for(int i=s.length();i<32;i++) { s+=0; } long sum=0,x=1; for(int i=31;i>=0;i--) { if(s.charAt(i)=='1') sum+=(x); x*=2; } out.print(sum); out.flush(); } }E:L1-5 演唱会
直接把时间写成一个六位数,分别于173727和193727比较即可;
import java.math.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.*; public class Main { public static void main(String args[])throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); Scanner input = new Scanner(System.in); String s = input.nextLine(); int p1=0,p2=0; for(int i=0;i<s.length();i++) { if(p1!=0&&s.charAt(i)==':') p2 = i; if(p1==0&&s.charAt(i)==':') p1 = i; } String xx = s.substring(0,p1),yy = s.substring(p1+1,p2),zz = s.substring(p2+1); int x = Integer.parseInt(xx)*10000+Integer.parseInt(yy)*100+Integer.parseInt(zz); if(x<173727) System.out.print("arrive on time"); if(x>=173727&&x<193727) System.out.print("arrive late"); if(x>=193727) System.out.print("too late"); } }F:L1-6 分鸽子
典型的二分模板题
和之前那个每日一题里的华华给月月礼物基本一样,分小木棍那个。
在1和最大的值之间二分查找,够分的肉的最大值输出即可。
import java.util.*; import java.math.*; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.PrintWriter; public class Main { public static void main(String args[])throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); in.nextToken(); int n = (int)in.nval; in.nextToken(); int m = (int)in.nval; int num[] = new int[n]; for(int t=0;t<n;t++) { in.nextToken(); num[t] = (int)in.nval; } int sum=0; Arrays.sort(num); int l=1,r=num[n-1],mid=(l+r)>>1,max=0; while(l<=r) { mid=(l+r)>>1; if(check(mid,num)>=m) { max = Math.max(max,mid); l = mid+1; } else{ r = mid-1; } } out.print(max); out.flush(); } public static int check(int p,int num[]) { int sum=0; for(int i=0;i<num.length;i++) { sum+=(num[i]/p); } return sum; } }G:L1-7 拼接梯子
分两种情况:
1.不能被2整除也就是最后一位二进制为1的,这样不可能凑成;
2.能被2整除的,直接看最大的那一位二进制的位置是否在拥有的种类中。
附加一个快速幂。
import java.util.*; import java.math.*; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.PrintWriter; public class Main { public static void main(String args[])throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); in.nextToken(); int k = (int) in.nval; in.nextToken(); long l = (long) in.nval; long sum = 0, L = l, p = 0; if ((l & 1) == 1) out.print("No"); else { while (L > 0) { if ((L & 1) == 1) sum = p; p++; L >>= 1; } if (sum <= k) { out.println("Yes"); out.println(pow(2, sum)); } else out.print("No"); } out.flush(); } public static long pow(long n,long x) { long temp=n,sum=1; while(x>0) { if((x&1)==1) { sum*=temp; } temp*=temp; x>>=1; } return sum; } }