zoukankan      html  css  js  c++  java
  • ACM1005

    这道题也很简单,就是计算圆的面积。

    在每一年土地都会被腐蚀,腐蚀的速度是每一年50平方。计算给一点,这点将在哪一年被腐蚀。

    C++代码:

    View Code
     1 #include <iostream>
    2 #include <math.h>
    3 #include <vector>
    4 #define IP 3.1415926
    5 using namespace std;
    6
    7 int main ()
    8 {
    9 int n;
    10 vector<int> m_num;//装下需要多少年
    11 while ( cin>>n )
    12 {
    13 double m_x,m_y;
    14 while ( n-- && cin>>m_x>>m_y )//x,y的坐标
    15 {
    16 double m_sum=IP*(m_x*m_x+m_y*m_y)/(double)2;//计算面积
    17 double m = m_sum/(double)50;//通过除,得到要多少年
    18 int m_tem=m;//有可能还未到整年
    19 if( m - (double)m_tem>1e-6)m_tem++;//多加一年
    20 m_num.push_back(m_tem);//保存
    21 }
    22 for ( vector<int>::size_type i=0;i!=m_num.size();++i)//输出
    23 {
    24 cout<<"Property "<<i+1<<": This property will begin eroding in year "<<m_num[i]<<"."<<endl;
    25 }
    26 cout<<"END OF OUTPUT."<<endl;
    27 m_num.clear();
    28 }
    29
    30 return 0;
    31 }

     java代码:

    View Code
     1 import java.io.*;
    2 import java.util.*;
    3 import java.lang.Math;
    4
    5 public class six
    6 {
    7 public static void main(String args[])throws Exception
    8 {
    9 int n;
    10 Scanner in=new Scanner(System.in);
    11 Vector<Integer> m_num=new Vector<Integer>();
    12
    13 while(in.hasNext())
    14 {
    15 n=in.nextInt();
    16 double m_x,m_y;
    17 while((n--)>0&&in.hasNext())
    18 {
    19 m_x=in.nextDouble();
    20 m_y=in.nextDouble();
    21 double m_sum=Math.PI*(m_x*m_x+m_y*m_y)/2;
    22 m_sum=m_sum/(double)50;
    23 int m=(int)m_sum;
    24 if((m_sum-m)>1e-6)m++;
    25 Integer m_p=new Integer(m);
    26 m_num.add(m_p);
    27 }
    28 for(int i=0;i<m_num.size();++i)
    29 {
    30 System.out.println("Property "+(i+1)+": This property will begin eroding in year "+m_num.get(i)+".");
    31 }
    32 System.out.println("END OF OUTPUT.");
    33 }
    34 }
    35 }

    可能很多地方与C++类似,但是为了学java,就这样也挺好的。

  • 相关阅读:
    mysql 主从备份
    ELK 日志系统
    rsync+inotify 实现自动同步
    yum 的 group的信息
    Centos yum 命令行 安装KDE Desktop
    centos 配置本地yum源
    关于抽象在解耦的作用
    linux 查看当前系统下的所有用户的名称
    Qthread的使用方法
    linux command 4
  • 原文地址:https://www.cnblogs.com/leewiki/p/2286359.html
Copyright © 2011-2022 走看看