知识点:
1.IPV6
2.C++ virtual void
3.PV操作
4.浏览GDB历史命令快捷键
5.地址块
6.TableLayout
7.无向树阶数
8.Message.what
9.Android.xml命名规则
10.netstat命令
11.BF算法
12.E-R图
13.文件目录遍历
编程题1.小度机器人
- public class XiaoDuRobot {
- public static int[] getLocation(int x0,int y0,String orders){
- int[] L={-1,0};
- int[] R={1,0};
- int[] U={0,1};
- int[] D={0,-1};
- int fx=x0;
- int fy=y0;
- for(int i=0;i<orders.length();i++){
- char order=orders.charAt(i);
- if(order=='L'){
- fx=fx+L[0];
- fy=fy+L[1];
- }else if(order=='R'){
- fx=fx+R[0];
- fy=fy+R[1];
- }else if(order=='U'){
- fx=fx+U[0];
- fy=fy+U[1];
- }else {
- fx=fx+D[0];
- fy=fy+D[1];
- }
- }
- int [] result=new int[2];
- result[0]=fx;
- result[1]=fy;
- return result;
- }
- public static void main(String[] args) {
- Scanner scanner=new Scanner(System.in);
- int x0=scanner.nextInt();
- int y0=scanner.nextInt();
- String orders=scanner.next();
- int[] result=getLocation(x0,y0,orders);
- System.out.println(result[0]+" "+result[1]);
- }
- }
- public class imageIllusion {
- public static int[][] averagePooling(int[][] image){
- int n=image.length;
- int m=image[0].length;
- if(n==0||m==0) return new int[n][m];
- int[][] directions={{1,0},{-1,0},{0,1},{0,-1}};
- for(int i=0;i<n;i++)
- for(int j=0;j<m;j++){
- int sum=image[i][j];
- int count=1;
- for(int k=0;k<4;k++){
- int temp=0;
- int newX=i+directions[k][0];
- int newY=j+directions[k][1];
- if(newX<0||newX>=n||newY<0||newY>=m){
- sum+=temp;
- }else{
- sum+=image[newX][newY];
- count++;
- }
- }
- int res= (int) Math.round(sum/(double) count);
- image[i][j]=res;
- }
- return image;
- }
- public static void main(String[] args) {
- Scanner scanner=new Scanner(System.in);
- int n=scanner.nextInt();
- int m=scanner.nextInt();
- int[][] image=new int[n][m];
- for(int i=0;i<n;i++)
- for(int j=0;j<m;j++){
- image[i][j]=scanner.nextInt();
- }
- int[][] result=averagePooling(image);
- for(int i=0;i<n;i++) {
- for (int j = 0; j < m; j++) {
- System.out.print(result[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
- public class lihuaSouvenir {
- public static int maxSou(int n,int m,int k,int[][] sou){
- Arrays.sort(sou,(a,b)->(a[2]!=b[2])?b[2]-a[2]:a[0]-b[0]);
- int count=0;
- int weight=0;
- int money=0;
- while(weight<=m&&money<=k&&count<=n){
- weight+=sou[count][1];
- money+=sou[count][0];
- if(weight<=m&&money<=k&&count<=n) {
- count++;
- }
- }
- return count;
- }
- public static void main(String[] args) {
- Scanner scanner=new Scanner(System.in);
- int n=scanner.nextInt();
- int m=scanner.nextInt();
- int k=scanner.nextInt();
- int[][] souvenirs=new int[n][3];
- for(int i=0;i<n;i++)
- for(int j=0;j<3;j++){
- souvenirs[i][j]=scanner.nextInt();
- }
- int result=maxSou(n,m,k,souvenirs);
- System.out.println(result);
- }
- }
全部评论
(0) 回帖