Problem A Liu Hai(2018acm热身赛)

 

/*Problem A Liu Hai
Time limit:1seconds
Every one knows that iphone x has liu hai.
每个人都知道iphone x有刘海
Suppose liu hai is a polygon like that.
假设刘海是这样的一个多边形
What's the area of iphone x's liu hai?
iphone x的刘海的面积是多少?
Input
输入
Just one case.
只有一个案例
First line a single integer n(1<=n<=10^5).
第一行一个整数n(1<=n<=10^5).
Then n lines, each line contains two integer x,y.
然后n行,每一行包含两个整数x,y。
We guarantee that x is increasing.
我们保证x在增加。
Output
输出
Print the answer with two decimal numbers.
输出答案保留两位小数。
Sample Input
3
0 0
2 2
4 0
Sample Output
4.00
 */
import java.util.Scanner;
public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //输入坐标个数
        int n = sc.nextInt();
        double num =0;
        int[][] arr = new int[n][2];
        //输入坐标
        for(int i=0;i<n;i++){
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }
        for(int i=0;i<n-1;i++){
            num+=area(arr[i][0],arr[i][1],arr[i+1][0],arr[i+1][1]);
        }
        System.out.printf("%.2f",num);
    }
   //计算两点之间形成的图形面积
    public static double area(int x1,int y1,int x2,int y2){
        x1 = x2 - x1;
        y1 = y1+y2;
        return x1*y1/2.0;
    }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值