zoukankan      html  css  js  c++  java
  • 用Java语言做ACM的注意事项

    ①用Java时只需要粘贴包里面的内容,包名是不需要的。//有包名的去掉包名

    ②提交题目时类名一定要是 Main,否则判题系统是不认识代码的。

      ③Java的util类里面的Scanner.in里面的 input(自己定义的输入类名).hasNext();用于判断输入数据是否结束非常好用,比起C/C++的EOF/NULL好用

    例题

    import java.util.Scanner;
    public class Main{
       public static void main(String[] args){
           Scanner input=new Scanner(System.in);
           while(true){
               int a=input.nextInt(), b=input.nextInt();
               if(a==0 && b==0)
                   break;
               System.out.println(a+b);
           }
       }
    }
    View Code
    import java.util.Scanner;
    public class Main{
       public static void main(String[] args){
           Scanner input=new Scanner(System.in);
           int n=input.nextInt();
           while((n--)!=0){
               int sum=0,m=input.nextInt();
               for(int i=0;i<m;i++)
                   sum+=input.nextInt();
               System.out.println(sum);
               if(n>0)
               System.out.println();
           }
       }
    }
    View Code

    暂时就这么多了

    附上一个简单数学题

    ZOJ Problem Set - 3203 Light Bulb

     1 import java.util.Scanner;
     2 
     3 public class Main {
     4     
     5     public static void main(String[] args)
     6     {
     7     
     8     Scanner    scanner = new Scanner(System.in);
     9          //   int T;
    10            // double H1,h1,D1;
    11             int  T1 = scanner.nextInt();
    12             while(T1!=0)
    13             {
    14                 T1--;
    15                 double H1 = scanner.nextDouble();
    16                 double h1 = scanner.nextDouble();
    17                 double D1 = scanner.nextDouble();
    18                 double temp=Math.sqrt((H1-h1)*D1);
    19                 double temp2=(H1-h1)*D1/H1;
    20                 if(temp>=D1)
    21                     System.out.println(String.format("%.3f",h1));
    22                     //printf("%.3lf
    ",h1);
    23                 else if(temp<temp2)
    24                     System.out.println(String.format("%.3f",h1*D1/H1));
    25                 //    printf("%.3lf
    ",h1*D1/H1);
    26                 else
    27                 {
    28                     double ans=D1+H1-temp-(H1-h1)*D1/temp;
    29              
    30                    System.out.println(String.format("%.3f", ans));
    31                 }
    32             }
    33            
    34         }
    35 
    36 
    37     }
    View Code

    其他以后补充

  • 相关阅读:
    taotao-manager-service/pom.xml
    Grafana+Prometheus 监控 MySQL
    firewall-cmd 常用命令
    K8S 容器的资源需求、资源限制
    K8S 高级调度方式
    性能测试工具 Locust 安装
    cookie 和 session区别
    K8S 调度器,预选策略,优选函数
    CPU 实用工具
    *(int*)&p
  • 原文地址:https://www.cnblogs.com/DWVictor/p/10187112.html
Copyright © 2011-2022 走看看